<!DOCTYPE html>
<html lang="en-US" dir="ltr">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,initial-scale=1">
    <title>Python3开发 | 中华文档库</title>
    <meta name="description" content="A VitePress site">
    <link rel="preload stylesheet" href="/docs/assets/style.beebbf61.css" as="style">
    <script type="module" src="/docs/assets/app.65379622.js"></script>
    <link rel="preload" href="/docs/assets/inter-roman-latin.2ed14f66.woff2" as="font" type="font/woff2" crossorigin="">
  <link rel="modulepreload" href="/docs/assets/chunks/framework.9a026969.js">
  <link rel="modulepreload" href="/docs/assets/chunks/theme.f887af6c.js">
  <link rel="modulepreload" href="/docs/assets/backend_python.md.a9236c98.lean.js">
  <link rel="icon" type="image/svg+xml" href="https://foruda.gitee.com/avatar/1662445450649625813/1624674_except-one_1662445449.png">
  <meta name="description" content="Libraries created by VitePress">
  <meta name="keywords" content="JavaScript,Laravel,Thinkphp,Python,Node,Vue3">
  <meta name="author" content="deeperee">
  <script id="check-dark-light">(()=>{const e=localStorage.getItem("vitepress-theme-appearance")||"",a=window.matchMedia("(prefers-color-scheme: dark)").matches;(!e||e==="auto"?a:e==="dark")&&document.documentElement.classList.add("dark")})();</script>
  </head>
  <body>
    <div id="app"><div class="Layout" data-v-4f197c35><!--[--><!--]--><!--[--><span tabindex="-1" data-v-398deaa1></span><a href="#VPContent" class="VPSkipLink visually-hidden" data-v-398deaa1> Skip to content </a><!--]--><!----><header class="VPNav" data-v-4f197c35 data-v-e55c7d48><div class="VPNavBar has-sidebar" data-v-e55c7d48 data-v-b81b2d2a><div class="container" data-v-b81b2d2a><div class="title" data-v-b81b2d2a><div class="VPNavBarTitle has-sidebar" data-v-b81b2d2a data-v-7290950d><a class="title" href="/docs/" data-v-7290950d><!--[--><!--]--><!--[--><img class="VPImage logo" src="https://foruda.gitee.com/avatar/1662445450649625813/1624674_except-one_1662445449.png" alt data-v-e8fda39b><!--]--><!--[-->中华文档库<!--]--><!--[--><!--]--></a></div></div><div class="content" data-v-b81b2d2a><div class="curtain" data-v-b81b2d2a></div><div class="content-body" data-v-b81b2d2a><!--[--><!--]--><div class="VPNavBarSearch search" style="--vp-meta-key:&#39;Meta&#39;;" data-v-b81b2d2a><!--[--><!----><div id="local-search"><button type="button" class="DocSearch DocSearch-Button" aria-label="Search"><span class="DocSearch-Button-Container"><svg class="DocSearch-Search-Icon" width="20" height="20" viewBox="0 0 20 20" aria-label="search icon"><path d="M14.386 14.386l4.0877 4.0877-4.0877-4.0877c-2.9418 2.9419-7.7115 2.9419-10.6533 0-2.9419-2.9418-2.9419-7.7115 0-10.6533 2.9418-2.9419 7.7115-2.9419 10.6533 0 2.9419 2.9418 2.9419 7.7115 0 10.6533z" stroke="currentColor" fill="none" fill-rule="evenodd" stroke-linecap="round" stroke-linejoin="round"></path></svg><span class="DocSearch-Button-Placeholder">Search</span></span><span class="DocSearch-Button-Keys"><kbd class="DocSearch-Button-Key"></kbd><kbd class="DocSearch-Button-Key">K</kbd></span></button></div><!--]--></div><nav aria-labelledby="main-nav-aria-label" class="VPNavBarMenu menu" data-v-b81b2d2a data-v-eca4ce12><span id="main-nav-aria-label" class="visually-hidden" data-v-eca4ce12>Main Navigation</span><!--[--><!--[--><a class="VPLink link VPNavBarMenuLink" href="/docs/sharp-sword/" tabindex="0" data-v-eca4ce12 data-v-07e518bf data-v-b5ae80c8><!--[-->利剑<!--]--><!----></a><!--]--><!--[--><a class="VPLink link VPNavBarMenuLink" href="/docs/frontend/" tabindex="0" data-v-eca4ce12 data-v-07e518bf data-v-b5ae80c8><!--[-->前端<!--]--><!----></a><!--]--><!--[--><a class="VPLink link VPNavBarMenuLink active" href="/docs/backend/" tabindex="0" data-v-eca4ce12 data-v-07e518bf data-v-b5ae80c8><!--[-->后端<!--]--><!----></a><!--]--><!--[--><a class="VPLink link VPNavBarMenuLink" href="/docs/environment/" tabindex="0" data-v-eca4ce12 data-v-07e518bf data-v-b5ae80c8><!--[-->服务<!--]--><!----></a><!--]--><!--[--><a class="VPLink link VPNavBarMenuLink" href="/docs/software/" tabindex="0" data-v-eca4ce12 data-v-07e518bf data-v-b5ae80c8><!--[-->软件<!--]--><!----></a><!--]--><!--]--></nav><!----><div class="VPNavBarAppearance appearance" data-v-b81b2d2a data-v-409d64f6><button class="VPSwitch VPSwitchAppearance" type="button" role="switch" title="toggle dark mode" aria-checked="false" data-v-409d64f6 data-v-94efbe2e data-v-d6a5970a><span class="check" data-v-d6a5970a><span class="icon" data-v-d6a5970a><!--[--><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" viewbox="0 0 24 24" class="sun" data-v-94efbe2e><path d="M12,18c-3.3,0-6-2.7-6-6s2.7-6,6-6s6,2.7,6,6S15.3,18,12,18zM12,8c-2.2,0-4,1.8-4,4c0,2.2,1.8,4,4,4c2.2,0,4-1.8,4-4C16,9.8,14.2,8,12,8z"></path><path d="M12,4c-0.6,0-1-0.4-1-1V1c0-0.6,0.4-1,1-1s1,0.4,1,1v2C13,3.6,12.6,4,12,4z"></path><path d="M12,24c-0.6,0-1-0.4-1-1v-2c0-0.6,0.4-1,1-1s1,0.4,1,1v2C13,23.6,12.6,24,12,24z"></path><path d="M5.6,6.6c-0.3,0-0.5-0.1-0.7-0.3L3.5,4.9c-0.4-0.4-0.4-1,0-1.4s1-0.4,1.4,0l1.4,1.4c0.4,0.4,0.4,1,0,1.4C6.2,6.5,5.9,6.6,5.6,6.6z"></path><path d="M19.8,20.8c-0.3,0-0.5-0.1-0.7-0.3l-1.4-1.4c-0.4-0.4-0.4-1,0-1.4s1-0.4,1.4,0l1.4,1.4c0.4,0.4,0.4,1,0,1.4C20.3,20.7,20,20.8,19.8,20.8z"></path><path d="M3,13H1c-0.6,0-1-0.4-1-1s0.4-1,1-1h2c0.6,0,1,0.4,1,1S3.6,13,3,13z"></path><path d="M23,13h-2c-0.6,0-1-0.4-1-1s0.4-1,1-1h2c0.6,0,1,0.4,1,1S23.6,13,23,13z"></path><path d="M4.2,20.8c-0.3,0-0.5-0.1-0.7-0.3c-0.4-0.4-0.4-1,0-1.4l1.4-1.4c0.4-0.4,1-0.4,1.4,0s0.4,1,0,1.4l-1.4,1.4C4.7,20.7,4.5,20.8,4.2,20.8z"></path><path d="M18.4,6.6c-0.3,0-0.5-0.1-0.7-0.3c-0.4-0.4-0.4-1,0-1.4l1.4-1.4c0.4-0.4,1-0.4,1.4,0s0.4,1,0,1.4l-1.4,1.4C18.9,6.5,18.6,6.6,18.4,6.6z"></path></svg><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" viewbox="0 0 24 24" class="moon" data-v-94efbe2e><path d="M12.1,22c-0.3,0-0.6,0-0.9,0c-5.5-0.5-9.5-5.4-9-10.9c0.4-4.8,4.2-8.6,9-9c0.4,0,0.8,0.2,1,0.5c0.2,0.3,0.2,0.8-0.1,1.1c-2,2.7-1.4,6.4,1.3,8.4c2.1,1.6,5,1.6,7.1,0c0.3-0.2,0.7-0.3,1.1-0.1c0.3,0.2,0.5,0.6,0.5,1c-0.2,2.7-1.5,5.1-3.6,6.8C16.6,21.2,14.4,22,12.1,22zM9.3,4.4c-2.9,1-5,3.6-5.2,6.8c-0.4,4.4,2.8,8.3,7.2,8.7c2.1,0.2,4.2-0.4,5.8-1.8c1.1-0.9,1.9-2.1,2.4-3.4c-2.5,0.9-5.3,0.5-7.5-1.1C9.2,11.4,8.1,7.7,9.3,4.4z"></path></svg><!--]--></span></span></button></div><div class="VPSocialLinks VPNavBarSocialLinks social-links" data-v-b81b2d2a data-v-1d3ce246 data-v-4a9f6b90><!--[--><a class="VPSocialLink" href="https://gitee.com/Except-one/" aria-label="github" target="_blank" rel="noopener" data-v-4a9f6b90 data-v-6de7ee81><svg role="img" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><title>GitHub</title><path d="M12 .297c-6.63 0-12 5.373-12 12 0 5.303 3.438 9.8 8.205 11.385.6.113.82-.258.82-.577 0-.285-.01-1.04-.015-2.04-3.338.724-4.042-1.61-4.042-1.61C4.422 18.07 3.633 17.7 3.633 17.7c-1.087-.744.084-.729.084-.729 1.205.084 1.838 1.236 1.838 1.236 1.07 1.835 2.809 1.305 3.495.998.108-.776.417-1.305.76-1.605-2.665-.3-5.466-1.332-5.466-5.93 0-1.31.465-2.38 1.235-3.22-.135-.303-.54-1.523.105-3.176 0 0 1.005-.322 3.3 1.23.96-.267 1.98-.399 3-.405 1.02.006 2.04.138 3 .405 2.28-1.552 3.285-1.23 3.285-1.23.645 1.653.24 2.873.12 3.176.765.84 1.23 1.91 1.23 3.22 0 4.61-2.805 5.625-5.475 5.92.42.36.81 1.096.81 2.22 0 1.606-.015 2.896-.015 3.286 0 .315.21.69.825.57C20.565 22.092 24 17.592 24 12.297c0-6.627-5.373-12-12-12"/></svg></a><a class="VPSocialLink" href="https://github.com/deeperee/" aria-label="github" target="_blank" rel="noopener" data-v-4a9f6b90 data-v-6de7ee81><svg role="img" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><title>GitHub</title><path d="M12 .297c-6.63 0-12 5.373-12 12 0 5.303 3.438 9.8 8.205 11.385.6.113.82-.258.82-.577 0-.285-.01-1.04-.015-2.04-3.338.724-4.042-1.61-4.042-1.61C4.422 18.07 3.633 17.7 3.633 17.7c-1.087-.744.084-.729.084-.729 1.205.084 1.838 1.236 1.838 1.236 1.07 1.835 2.809 1.305 3.495.998.108-.776.417-1.305.76-1.605-2.665-.3-5.466-1.332-5.466-5.93 0-1.31.465-2.38 1.235-3.22-.135-.303-.54-1.523.105-3.176 0 0 1.005-.322 3.3 1.23.96-.267 1.98-.399 3-.405 1.02.006 2.04.138 3 .405 2.28-1.552 3.285-1.23 3.285-1.23.645 1.653.24 2.873.12 3.176.765.84 1.23 1.91 1.23 3.22 0 4.61-2.805 5.625-5.475 5.92.42.36.81 1.096.81 2.22 0 1.606-.015 2.896-.015 3.286 0 .315.21.69.825.57C20.565 22.092 24 17.592 24 12.297c0-6.627-5.373-12-12-12"/></svg></a><!--]--></div><div class="VPFlyout VPNavBarExtra extra" data-v-b81b2d2a data-v-6d7ae577 data-v-541ff04c><button type="button" class="button" aria-haspopup="true" aria-expanded="false" aria-label="extra navigation" data-v-541ff04c><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" viewbox="0 0 24 24" class="icon" data-v-541ff04c><circle cx="12" cy="12" r="2"></circle><circle cx="19" cy="12" r="2"></circle><circle cx="5" cy="12" r="2"></circle></svg></button><div class="menu" data-v-541ff04c><div class="VPMenu" data-v-541ff04c data-v-8a79d938><!----><!--[--><!--[--><!----><div class="group" data-v-6d7ae577><div class="item appearance" data-v-6d7ae577><p class="label" data-v-6d7ae577>Appearance</p><div class="appearance-action" data-v-6d7ae577><button class="VPSwitch VPSwitchAppearance" type="button" role="switch" title="toggle dark mode" aria-checked="false" data-v-6d7ae577 data-v-94efbe2e data-v-d6a5970a><span class="check" data-v-d6a5970a><span class="icon" data-v-d6a5970a><!--[--><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" viewbox="0 0 24 24" class="sun" data-v-94efbe2e><path d="M12,18c-3.3,0-6-2.7-6-6s2.7-6,6-6s6,2.7,6,6S15.3,18,12,18zM12,8c-2.2,0-4,1.8-4,4c0,2.2,1.8,4,4,4c2.2,0,4-1.8,4-4C16,9.8,14.2,8,12,8z"></path><path d="M12,4c-0.6,0-1-0.4-1-1V1c0-0.6,0.4-1,1-1s1,0.4,1,1v2C13,3.6,12.6,4,12,4z"></path><path d="M12,24c-0.6,0-1-0.4-1-1v-2c0-0.6,0.4-1,1-1s1,0.4,1,1v2C13,23.6,12.6,24,12,24z"></path><path d="M5.6,6.6c-0.3,0-0.5-0.1-0.7-0.3L3.5,4.9c-0.4-0.4-0.4-1,0-1.4s1-0.4,1.4,0l1.4,1.4c0.4,0.4,0.4,1,0,1.4C6.2,6.5,5.9,6.6,5.6,6.6z"></path><path d="M19.8,20.8c-0.3,0-0.5-0.1-0.7-0.3l-1.4-1.4c-0.4-0.4-0.4-1,0-1.4s1-0.4,1.4,0l1.4,1.4c0.4,0.4,0.4,1,0,1.4C20.3,20.7,20,20.8,19.8,20.8z"></path><path d="M3,13H1c-0.6,0-1-0.4-1-1s0.4-1,1-1h2c0.6,0,1,0.4,1,1S3.6,13,3,13z"></path><path d="M23,13h-2c-0.6,0-1-0.4-1-1s0.4-1,1-1h2c0.6,0,1,0.4,1,1S23.6,13,23,13z"></path><path d="M4.2,20.8c-0.3,0-0.5-0.1-0.7-0.3c-0.4-0.4-0.4-1,0-1.4l1.4-1.4c0.4-0.4,1-0.4,1.4,0s0.4,1,0,1.4l-1.4,1.4C4.7,20.7,4.5,20.8,4.2,20.8z"></path><path d="M18.4,6.6c-0.3,0-0.5-0.1-0.7-0.3c-0.4-0.4-0.4-1,0-1.4l1.4-1.4c0.4-0.4,1-0.4,1.4,0s0.4,1,0,1.4l-1.4,1.4C18.9,6.5,18.6,6.6,18.4,6.6z"></path></svg><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" viewbox="0 0 24 24" class="moon" data-v-94efbe2e><path d="M12.1,22c-0.3,0-0.6,0-0.9,0c-5.5-0.5-9.5-5.4-9-10.9c0.4-4.8,4.2-8.6,9-9c0.4,0,0.8,0.2,1,0.5c0.2,0.3,0.2,0.8-0.1,1.1c-2,2.7-1.4,6.4,1.3,8.4c2.1,1.6,5,1.6,7.1,0c0.3-0.2,0.7-0.3,1.1-0.1c0.3,0.2,0.5,0.6,0.5,1c-0.2,2.7-1.5,5.1-3.6,6.8C16.6,21.2,14.4,22,12.1,22zM9.3,4.4c-2.9,1-5,3.6-5.2,6.8c-0.4,4.4,2.8,8.3,7.2,8.7c2.1,0.2,4.2-0.4,5.8-1.8c1.1-0.9,1.9-2.1,2.4-3.4c-2.5,0.9-5.3,0.5-7.5-1.1C9.2,11.4,8.1,7.7,9.3,4.4z"></path></svg><!--]--></span></span></button></div></div></div><div class="group" data-v-6d7ae577><div class="item social-links" data-v-6d7ae577><div class="VPSocialLinks social-links-list" data-v-6d7ae577 data-v-4a9f6b90><!--[--><a class="VPSocialLink" href="https://gitee.com/Except-one/" aria-label="github" target="_blank" rel="noopener" data-v-4a9f6b90 data-v-6de7ee81><svg role="img" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><title>GitHub</title><path d="M12 .297c-6.63 0-12 5.373-12 12 0 5.303 3.438 9.8 8.205 11.385.6.113.82-.258.82-.577 0-.285-.01-1.04-.015-2.04-3.338.724-4.042-1.61-4.042-1.61C4.422 18.07 3.633 17.7 3.633 17.7c-1.087-.744.084-.729.084-.729 1.205.084 1.838 1.236 1.838 1.236 1.07 1.835 2.809 1.305 3.495.998.108-.776.417-1.305.76-1.605-2.665-.3-5.466-1.332-5.466-5.93 0-1.31.465-2.38 1.235-3.22-.135-.303-.54-1.523.105-3.176 0 0 1.005-.322 3.3 1.23.96-.267 1.98-.399 3-.405 1.02.006 2.04.138 3 .405 2.28-1.552 3.285-1.23 3.285-1.23.645 1.653.24 2.873.12 3.176.765.84 1.23 1.91 1.23 3.22 0 4.61-2.805 5.625-5.475 5.92.42.36.81 1.096.81 2.22 0 1.606-.015 2.896-.015 3.286 0 .315.21.69.825.57C20.565 22.092 24 17.592 24 12.297c0-6.627-5.373-12-12-12"/></svg></a><a class="VPSocialLink" href="https://github.com/deeperee/" aria-label="github" target="_blank" rel="noopener" data-v-4a9f6b90 data-v-6de7ee81><svg role="img" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><title>GitHub</title><path d="M12 .297c-6.63 0-12 5.373-12 12 0 5.303 3.438 9.8 8.205 11.385.6.113.82-.258.82-.577 0-.285-.01-1.04-.015-2.04-3.338.724-4.042-1.61-4.042-1.61C4.422 18.07 3.633 17.7 3.633 17.7c-1.087-.744.084-.729.084-.729 1.205.084 1.838 1.236 1.838 1.236 1.07 1.835 2.809 1.305 3.495.998.108-.776.417-1.305.76-1.605-2.665-.3-5.466-1.332-5.466-5.93 0-1.31.465-2.38 1.235-3.22-.135-.303-.54-1.523.105-3.176 0 0 1.005-.322 3.3 1.23.96-.267 1.98-.399 3-.405 1.02.006 2.04.138 3 .405 2.28-1.552 3.285-1.23 3.285-1.23.645 1.653.24 2.873.12 3.176.765.84 1.23 1.91 1.23 3.22 0 4.61-2.805 5.625-5.475 5.92.42.36.81 1.096.81 2.22 0 1.606-.015 2.896-.015 3.286 0 .315.21.69.825.57C20.565 22.092 24 17.592 24 12.297c0-6.627-5.373-12-12-12"/></svg></a><!--]--></div></div></div><!--]--><!--]--></div></div></div><!--[--><!--]--><button type="button" class="VPNavBarHamburger hamburger" aria-label="mobile navigation" aria-expanded="false" aria-controls="VPNavScreen" data-v-b81b2d2a data-v-7744d315><span class="container" data-v-7744d315><span class="top" data-v-7744d315></span><span class="middle" data-v-7744d315></span><span class="bottom" data-v-7744d315></span></span></button></div></div></div></div><!----></header><div class="VPLocalNav" data-v-4f197c35 data-v-80ba5e0c><button class="menu" aria-expanded="false" aria-controls="VPSidebarNav" data-v-80ba5e0c><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" viewbox="0 0 24 24" class="menu-icon" data-v-80ba5e0c><path d="M17,11H3c-0.6,0-1-0.4-1-1s0.4-1,1-1h14c0.6,0,1,0.4,1,1S17.6,11,17,11z"></path><path d="M21,7H3C2.4,7,2,6.6,2,6s0.4-1,1-1h18c0.6,0,1,0.4,1,1S21.6,7,21,7z"></path><path d="M21,15H3c-0.6,0-1-0.4-1-1s0.4-1,1-1h18c0.6,0,1,0.4,1,1S21.6,15,21,15z"></path><path d="M17,19H3c-0.6,0-1-0.4-1-1s0.4-1,1-1h14c0.6,0,1,0.4,1,1S17.6,19,17,19z"></path></svg><span class="menu-text" data-v-80ba5e0c>Menu</span></button><div class="VPLocalNavOutlineDropdown" style="--vp-vh:0px;" data-v-80ba5e0c data-v-96e3780d><button data-v-96e3780d>Return to top</button><!----></div></div><aside class="VPSidebar" data-v-4f197c35 data-v-b6f99f93><div class="curtain" data-v-b6f99f93></div><nav class="nav" id="VPSidebarNav" aria-labelledby="sidebar-aria-label" tabindex="-1" data-v-b6f99f93><span class="visually-hidden" id="sidebar-aria-label" data-v-b6f99f93> Sidebar Navigation </span><!--[--><!--]--><!--[--><div class="group" data-v-b6f99f93><section class="VPSidebarItem level-0 has-active" data-v-b6f99f93 data-v-e89623a4><!----><div class="items" data-v-e89623a4><!--[--><div class="VPSidebarItem level-1 is-link" data-v-e89623a4 data-v-e89623a4><div class="item" data-v-e89623a4><div class="indicator" data-v-e89623a4></div><a class="VPLink link link" href="/docs/backend/index.html" data-v-e89623a4 data-v-b5ae80c8><!--[--><p class="text" data-v-e89623a4>HTTP状态码</p><!--]--><!----></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-e89623a4 data-v-e89623a4><div class="item" data-v-e89623a4><div class="indicator" data-v-e89623a4></div><a class="VPLink link link" href="/docs/backend/api.html" data-v-e89623a4 data-v-b5ae80c8><!--[--><p class="text" data-v-e89623a4>API开发</p><!--]--><!----></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-e89623a4 data-v-e89623a4><div class="item" data-v-e89623a4><div class="indicator" data-v-e89623a4></div><a class="VPLink link link" href="/docs/backend/composer.html" data-v-e89623a4 data-v-b5ae80c8><!--[--><p class="text" data-v-e89623a4>Composer</p><!--]--><!----></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-e89623a4 data-v-e89623a4><div class="item" data-v-e89623a4><div class="indicator" data-v-e89623a4></div><a class="VPLink link link" href="/docs/backend/database.html" data-v-e89623a4 data-v-b5ae80c8><!--[--><p class="text" data-v-e89623a4>Database</p><!--]--><!----></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-e89623a4 data-v-e89623a4><div class="item" data-v-e89623a4><div class="indicator" data-v-e89623a4></div><a class="VPLink link link" href="/docs/backend/laravel.html" data-v-e89623a4 data-v-b5ae80c8><!--[--><p class="text" data-v-e89623a4>Laravel 8.x</p><!--]--><!----></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-e89623a4 data-v-e89623a4><div class="item" data-v-e89623a4><div class="indicator" data-v-e89623a4></div><a class="VPLink link link" href="/docs/backend/thinkphp6.html" data-v-e89623a4 data-v-b5ae80c8><!--[--><p class="text" data-v-e89623a4>ThinkPHP 6.x</p><!--]--><!----></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-e89623a4 data-v-e89623a4><div class="item" data-v-e89623a4><div class="indicator" data-v-e89623a4></div><a class="VPLink link link" href="/docs/backend/fast-admin.html" data-v-e89623a4 data-v-b5ae80c8><!--[--><p class="text" data-v-e89623a4>Fast-admin</p><!--]--><!----></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-e89623a4 data-v-e89623a4><div class="item" data-v-e89623a4><div class="indicator" data-v-e89623a4></div><a class="VPLink link link" href="/docs/backend/php-advanced.html" data-v-e89623a4 data-v-b5ae80c8><!--[--><p class="text" data-v-e89623a4>PHP 高级函数</p><!--]--><!----></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-e89623a4 data-v-e89623a4><div class="item" data-v-e89623a4><div class="indicator" data-v-e89623a4></div><a class="VPLink link link" href="/docs/backend/php-bc-function.html" data-v-e89623a4 data-v-b5ae80c8><!--[--><p class="text" data-v-e89623a4>PHP BC运算函数</p><!--]--><!----></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-e89623a4 data-v-e89623a4><div class="item" data-v-e89623a4><div class="indicator" data-v-e89623a4></div><a class="VPLink link link" href="/docs/backend/php-vender.html" data-v-e89623a4 data-v-b5ae80c8><!--[--><p class="text" data-v-e89623a4>PHP 扩展插件</p><!--]--><!----></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link is-active has-active" data-v-e89623a4 data-v-e89623a4><div class="item" data-v-e89623a4><div class="indicator" data-v-e89623a4></div><a class="VPLink link link" href="/docs/backend/python.html" data-v-e89623a4 data-v-b5ae80c8><!--[--><p class="text" data-v-e89623a4>Python3</p><!--]--><!----></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-e89623a4 data-v-e89623a4><div class="item" data-v-e89623a4><div class="indicator" data-v-e89623a4></div><a class="VPLink link link" href="/docs/backend/shell.html" data-v-e89623a4 data-v-b5ae80c8><!--[--><p class="text" data-v-e89623a4>SHELL</p><!--]--><!----></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-e89623a4 data-v-e89623a4><div class="item" data-v-e89623a4><div class="indicator" data-v-e89623a4></div><a class="VPLink link link" href="/docs/backend/wechat.html" data-v-e89623a4 data-v-b5ae80c8><!--[--><p class="text" data-v-e89623a4>微信开发</p><!--]--><!----></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-e89623a4 data-v-e89623a4><div class="item" data-v-e89623a4><div class="indicator" data-v-e89623a4></div><a class="VPLink link link" href="/docs/backend/dollar.html" data-v-e89623a4 data-v-b5ae80c8><!--[--><p class="text" data-v-e89623a4>~~彩蛋~~</p><!--]--><!----></a><!----></div><!----></div><!--]--></div></section></div><!--]--><!--[--><!--]--></nav></aside><div class="VPContent has-sidebar" id="VPContent" data-v-4f197c35 data-v-251b6042><div class="VPDoc has-sidebar has-aside" data-v-251b6042 data-v-0618013c><!--[--><!--]--><div class="container" data-v-0618013c><div class="aside" data-v-0618013c><div class="aside-curtain" data-v-0618013c></div><div class="aside-container" data-v-0618013c><div class="aside-content" data-v-0618013c><div class="VPDocAside" data-v-0618013c data-v-a927bda4><!--[--><!--]--><!--[--><!--]--><div class="VPDocAsideOutline" data-v-a927bda4 data-v-aa3da25a><div class="content" data-v-aa3da25a><div class="outline-marker" data-v-aa3da25a></div><div class="outline-title" data-v-aa3da25a>On this page</div><nav aria-labelledby="doc-outline-aria-label" data-v-aa3da25a><span class="visually-hidden" id="doc-outline-aria-label" data-v-aa3da25a> Table of Contents for current page </span><ul class="root" data-v-aa3da25a data-v-c23508ae><!--[--><!--]--></ul></nav></div></div><!--[--><!--]--><div class="spacer" data-v-a927bda4></div><!--[--><!--]--><!----><!--[--><!--]--><!--[--><!--]--></div></div></div></div><div class="content" data-v-0618013c><div class="content-container" data-v-0618013c><!--[--><!--]--><!----><main class="main" data-v-0618013c><div style="position:relative;" class="vp-doc _docs_backend_python" data-v-0618013c><div><h1 id="python3开发" tabindex="-1">Python3开发 <a class="header-anchor" href="#python3开发" aria-label="Permalink to &quot;Python3开发&quot;">​</a></h1><h2 id="安装出现-timed-out-问题" tabindex="-1">安装出现（timed out）问题 <a class="header-anchor" href="#安装出现-timed-out-问题" aria-label="Permalink to &quot;安装出现（timed out）问题&quot;">​</a></h2><ul><li><p>切换数据源安装模块</p></li><li><p><a href="https://mirrors.aliyun.com/pypi/simple" target="_blank" rel="noreferrer">阿里源</a></p></li><li><p><a href="https://pypi.tuna.tsinghua.edu.cn/simple" target="_blank" rel="noreferrer">清华源</a></p></li><li><p><a href="https://pypi.douban.com/simple" target="_blank" rel="noreferrer">豆瓣源</a></p></li><li><p><a href="https://pypi.mirrors.ustc.edu.cn/simple" target="_blank" rel="noreferrer">中国科技大学</a></p></li><li><p>安装方式，如下：</p></li></ul><div class="language-python line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">python</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#A6ACCD;">pip config </span><span style="color:#FFCB6B;">set</span><span style="color:#A6ACCD;"> </span><span style="color:#C792EA;">global</span><span style="color:#89DDFF;">.</span><span style="color:#F07178;">index</span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">url https</span><span style="color:#89DDFF;">://</span><span style="color:#A6ACCD;">mirrors</span><span style="color:#89DDFF;">.</span><span style="color:#F07178;">aliyun</span><span style="color:#89DDFF;">.</span><span style="color:#F07178;">com</span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">pypi</span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">simple</span></span>
<span class="line"></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># 或者 临时切换安装模块</span></span>
<span class="line"><span style="color:#A6ACCD;">pip install </span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">i </span><span style="color:#89DDFF;">[</span><span style="color:#A6ACCD;">源地址</span><span style="color:#89DDFF;">]</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">[</span><span style="color:#A6ACCD;">安装模块名</span><span style="color:#89DDFF;">]</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br></div></div><h2 id="使用-jupyter-notebook-开发" tabindex="-1">使用 jupyter notebook 开发 <a class="header-anchor" href="#使用-jupyter-notebook-开发" aria-label="Permalink to &quot;使用 jupyter notebook 开发&quot;">​</a></h2><ul><li><p>安装方式：<code>pip install jupyter notebook</code></p></li><li><p>启动例一：<code>python3 -m IPython notebook</code></p></li><li><p>启动例二：<code>jupyter-notebook</code></p></li></ul><h2 id="基本数据类型" tabindex="-1">基本数据类型 <a class="header-anchor" href="#基本数据类型" aria-label="Permalink to &quot;基本数据类型&quot;">​</a></h2><blockquote><p>可变数据类型：list，dict，set</p><p>不可变数据类型：number，str，tuple</p></blockquote><table><thead><tr><th style="text-align:left;">类型</th><th>例子</th><th style="text-align:left;">说明</th><th>使用</th></tr></thead><tbody><tr><td style="text-align:left;">number</td><td>i, f, b, c = 3, 3.14, True, 3+4b</td><td style="text-align:left;">整数（int, float, bool, complex）</td><td>可多个变量一同声明</td></tr><tr><td style="text-align:left;">str</td><td>&#39;123&#39;</td><td style="text-align:left;">字符串</td><td></td></tr><tr><td style="text-align:left;">dict</td><td>t = &#39;{&quot;title&quot;: &quot;iPhone XR&quot;, &quot;prise&quot;: 688}&#39;</td><td style="text-align:left;">字典（其他语言中的 <code>json</code>）</td><td>t[&#39;prise&#39;] = 688</td></tr><tr><td style="text-align:left;">list</td><td>l = [&quot;iPhone XR&quot;, 688]</td><td style="text-align:left;">列表（其他语言中的<code>array</code>)</td><td>l[1] = 688</td></tr><tr><td style="text-align:left;">tuple</td><td>t = (&#39;PHP&#39;, &#39;Python&#39;, 123, 34.56)、 (123, )</td><td style="text-align:left;">元组（只有一个元素时，必须有逗号）</td><td>t[1] = Python</td></tr><tr><td style="text-align:left;">set</td><td>x = set(&#39;runoob&#39;)</td><td style="text-align:left;">集合自动去重，自动排序</td><td>&quot;{&#39;b&#39;, &#39;n&#39;, &#39;o&#39;, &#39;r&#39;, &#39;u&#39;}&quot;</td></tr></tbody></table><h2 id="单元格常用的数据类型" tabindex="-1">单元格常用的数据类型 <a class="header-anchor" href="#单元格常用的数据类型" aria-label="Permalink to &quot;单元格常用的数据类型&quot;">​</a></h2><ol><li>empty ---------- 空的</li><li>string --------- text</li><li>number --------- 数字</li><li>date ----------- 时间</li><li>boolean -------- 真假</li><li>error ---------- 错误</li><li>blank ---------- 空白表格</li></ol><h2 id="🎉-库的操作-安装一个库" tabindex="-1">🎉 库的操作 - 安装一个库 <a class="header-anchor" href="#🎉-库的操作-安装一个库" aria-label="Permalink to &quot;🎉 库的操作 - 安装一个库&quot;">​</a></h2><div class="language-shell line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#FFCB6B;">pip3</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">install</span><span style="color:#A6ACCD;"> [库名称]</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br></div></div><ul><li><p>pip3 install requests</p></li><li><p>pip3 install urllib</p></li><li><p>pip3 install pillow</p></li><li><p>pip3 install selenium</p><blockquote><p>浏览器驱动：<a href="https://registry.npmmirror.com/binary.html?path=chromedriver/" target="_blank" rel="noreferrer">https://registry.npmmirror.com/binary.html?path=chromedriver/</a></p></blockquote></li><li><p>pip3 install opency-python</p></li></ul><h2 id="查看库的版本" tabindex="-1">查看库的版本 <a class="header-anchor" href="#查看库的版本" aria-label="Permalink to &quot;查看库的版本&quot;">​</a></h2><div class="language-shell line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#89DDFF;">&gt;</span><span style="color:#A6ACCD;"> pip3 show opencv-python</span></span>
<span class="line"></span>
<span class="line"><span style="color:#FFCB6B;">Name:</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">opencv-python</span></span>
<span class="line"><span style="color:#FFCB6B;">Version:</span><span style="color:#A6ACCD;"> </span><span style="color:#F78C6C;">4.7</span><span style="color:#C3E88D;">.0.68</span></span>
<span class="line"><span style="color:#FFCB6B;">Summary:</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">Wrapper</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">package</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">for</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">OpenCV</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">python</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">bindings.</span></span>
<span class="line"><span style="color:#FFCB6B;">Home-page:</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">https://github.com/opencv/opencv-python</span></span>
<span class="line"><span style="color:#FFCB6B;">Author:</span><span style="color:#A6ACCD;"> </span></span>
<span class="line"><span style="color:#FFCB6B;">Author-email:</span><span style="color:#A6ACCD;"> </span></span>
<span class="line"><span style="color:#FFCB6B;">License:</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">MIT</span></span>
<span class="line"><span style="color:#FFCB6B;">Location:</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">/opt/homebrew/lib/python3.10/site-packages</span></span>
<span class="line"><span style="color:#FFCB6B;">Requires:</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">numpy,</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">numpy,</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">numpy,</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">numpy,</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">numpy</span></span>
<span class="line"><span style="color:#FFCB6B;">Required-by:</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br></div></div><h2 id="创建目录" tabindex="-1">创建目录 <a class="header-anchor" href="#创建目录" aria-label="Permalink to &quot;创建目录&quot;">​</a></h2><div class="language-py line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">py</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#89DDFF;font-style:italic;">import</span><span style="color:#A6ACCD;"> os</span></span>
<span class="line"></span>
<span class="line"><span style="color:#C792EA;">def</span><span style="color:#A6ACCD;"> </span><span style="color:#82AAFF;">mkdir</span><span style="color:#89DDFF;">(</span><span style="color:#A6ACCD;font-style:italic;">dirname</span><span style="color:#89DDFF;">):</span></span>
<span class="line"><span style="color:#A6ACCD;">  	dirname </span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;"> dirname</span><span style="color:#89DDFF;">[</span><span style="color:#F78C6C;">1</span><span style="color:#89DDFF;">:]</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;font-style:italic;">if</span><span style="color:#A6ACCD;"> dirname</span><span style="color:#89DDFF;">[:</span><span style="color:#F78C6C;">2</span><span style="color:#89DDFF;">]</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">==</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">&#39;</span><span style="color:#C3E88D;">./</span><span style="color:#89DDFF;">&#39;</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;font-style:italic;">else</span><span style="color:#A6ACCD;"> dirname</span></span>
<span class="line"><span style="color:#A6ACCD;">    dirname </span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;"> dirname </span><span style="color:#89DDFF;font-style:italic;">if</span><span style="color:#A6ACCD;"> dirname</span><span style="color:#89DDFF;">[:</span><span style="color:#F78C6C;">1</span><span style="color:#89DDFF;">]</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">==</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">&#39;</span><span style="color:#C3E88D;">/</span><span style="color:#89DDFF;">&#39;</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;font-style:italic;">else</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">&#39;</span><span style="color:#C3E88D;">/</span><span style="color:#89DDFF;">&#39;</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">+</span><span style="color:#A6ACCD;"> dirname</span></span>
<span class="line"><span style="color:#A6ACCD;">    </span></span>
<span class="line"><span style="color:#A6ACCD;">    path </span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;"> os</span><span style="color:#89DDFF;">.</span><span style="color:#F07178;">path</span><span style="color:#89DDFF;">.</span><span style="color:#82AAFF;">dirname</span><span style="color:#89DDFF;">(</span><span style="color:#A6ACCD;">__file__</span><span style="color:#89DDFF;">)</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">+</span><span style="color:#A6ACCD;"> dirname</span></span>
<span class="line"><span style="color:#A6ACCD;">    </span><span style="color:#89DDFF;font-style:italic;">if</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">not</span><span style="color:#A6ACCD;"> os</span><span style="color:#89DDFF;">.</span><span style="color:#F07178;">path</span><span style="color:#89DDFF;">.</span><span style="color:#82AAFF;">exists</span><span style="color:#89DDFF;">(</span><span style="color:#82AAFF;">path</span><span style="color:#89DDFF;">):</span></span>
<span class="line"><span style="color:#A6ACCD;">        os</span><span style="color:#89DDFF;">.</span><span style="color:#82AAFF;">mkdir</span><span style="color:#89DDFF;">(</span><span style="color:#82AAFF;">path</span><span style="color:#89DDFF;">)</span></span>
<span class="line"><span style="color:#A6ACCD;">    </span><span style="color:#89DDFF;font-style:italic;">return</span><span style="color:#A6ACCD;"> path</span></span>
<span class="line"></span>
<span class="line"><span style="color:#82AAFF;">print</span><span style="color:#89DDFF;">(</span><span style="color:#82AAFF;">mkdir</span><span style="color:#89DDFF;">(</span><span style="color:#89DDFF;">&#39;</span><span style="color:#C3E88D;">baobao/2023-02-02</span><span style="color:#89DDFF;">&#39;</span><span style="color:#89DDFF;">))</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># /Users/feeler/Documents/PY2020/采集QQ空间图片/qzone/baobao/2023-02-02</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br></div></div><h2 id="🎉-字典声明" tabindex="-1">🎉 字典声明 <a class="header-anchor" href="#🎉-字典声明" aria-label="Permalink to &quot;🎉 字典声明&quot;">​</a></h2><div class="language-python line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">python</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#676E95;font-style:italic;"># 声明一个字典</span></span>
<span class="line"><span style="color:#A6ACCD;">dic </span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">{}</span><span style="color:#A6ACCD;"> 			</span><span style="color:#676E95;font-style:italic;"># 或 dic = dict()</span></span>
<span class="line"><span style="color:#A6ACCD;">dic </span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">{</span><span style="color:#89DDFF;">&quot;</span><span style="color:#C3E88D;">id</span><span style="color:#89DDFF;">&quot;</span><span style="color:#89DDFF;">:</span><span style="color:#A6ACCD;"> </span><span style="color:#F78C6C;">123</span><span style="color:#89DDFF;">,</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">&quot;</span><span style="color:#C3E88D;">name</span><span style="color:#89DDFF;">&quot;</span><span style="color:#89DDFF;">:</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">&#39;</span><span style="color:#C3E88D;">deeper</span><span style="color:#89DDFF;">&#39;</span><span style="color:#89DDFF;">}</span><span style="color:#A6ACCD;"> </span><span style="color:#676E95;font-style:italic;"># 或 dic = dict({&quot;id&quot;: 123, &quot;name&quot;: &#39;deeper&#39;})</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br></div></div><h2 id="字典基本操作" tabindex="-1">字典基本操作 <a class="header-anchor" href="#字典基本操作" aria-label="Permalink to &quot;字典基本操作&quot;">​</a></h2><div class="language-python line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">python</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#A6ACCD;">dic </span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">{</span><span style="color:#89DDFF;">&quot;</span><span style="color:#C3E88D;">id</span><span style="color:#89DDFF;">&quot;</span><span style="color:#89DDFF;">:</span><span style="color:#A6ACCD;"> </span><span style="color:#F78C6C;">123</span><span style="color:#89DDFF;">,</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">&quot;</span><span style="color:#C3E88D;">name</span><span style="color:#89DDFF;">&quot;</span><span style="color:#89DDFF;">:</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">&#39;</span><span style="color:#C3E88D;">deeper</span><span style="color:#89DDFF;">&#39;</span><span style="color:#89DDFF;">}</span></span>
<span class="line"></span>
<span class="line"><span style="color:#89DDFF;font-style:italic;">&#39;&#39;&#39;</span><span style="color:#676E95;font-style:italic;">取值</span><span style="color:#89DDFF;font-style:italic;">&#39;&#39;&#39;</span></span>
<span class="line"><span style="color:#82AAFF;">print</span><span style="color:#89DDFF;">(</span><span style="color:#82AAFF;">dic</span><span style="color:#89DDFF;">[</span><span style="color:#89DDFF;">&#39;</span><span style="color:#C3E88D;">name</span><span style="color:#89DDFF;">&#39;</span><span style="color:#89DDFF;">])</span><span style="color:#A6ACCD;"> 			</span><span style="color:#676E95;font-style:italic;"># deeper</span></span>
<span class="line"><span style="color:#82AAFF;">print</span><span style="color:#89DDFF;">(</span><span style="color:#82AAFF;">dic</span><span style="color:#89DDFF;">.</span><span style="color:#82AAFF;">get</span><span style="color:#89DDFF;">(</span><span style="color:#89DDFF;">&#39;</span><span style="color:#C3E88D;">name</span><span style="color:#89DDFF;">&#39;</span><span style="color:#89DDFF;">))</span><span style="color:#A6ACCD;"> 	</span><span style="color:#676E95;font-style:italic;"># deeper</span></span>
<span class="line"><span style="color:#82AAFF;">print</span><span style="color:#89DDFF;">(</span><span style="color:#82AAFF;">dic</span><span style="color:#89DDFF;">.</span><span style="color:#82AAFF;">keys</span><span style="color:#89DDFF;">())</span><span style="color:#A6ACCD;"> 	</span><span style="color:#676E95;font-style:italic;"># dict_keys([&#39;id&#39;, &#39;name&#39;])</span></span>
<span class="line"><span style="color:#82AAFF;">print</span><span style="color:#89DDFF;">(</span><span style="color:#82AAFF;">dic</span><span style="color:#89DDFF;">.</span><span style="color:#82AAFF;">values</span><span style="color:#89DDFF;">())</span><span style="color:#A6ACCD;"> </span><span style="color:#676E95;font-style:italic;"># dict_values([3, &#39;deeper&#39;])</span></span>
<span class="line"></span>
<span class="line"></span>
<span class="line"><span style="color:#89DDFF;font-style:italic;">&#39;&#39;&#39;</span><span style="color:#676E95;font-style:italic;">追加 更新一个不存在的字典</span><span style="color:#89DDFF;font-style:italic;">&#39;&#39;&#39;</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># 方式一</span></span>
<span class="line"><span style="color:#A6ACCD;">dic</span><span style="color:#89DDFF;">.</span><span style="color:#82AAFF;">update</span><span style="color:#89DDFF;">({</span><span style="color:#89DDFF;">&#39;</span><span style="color:#C3E88D;">age</span><span style="color:#89DDFF;">&#39;</span><span style="color:#89DDFF;">:</span><span style="color:#F78C6C;">24</span><span style="color:#89DDFF;">})</span></span>
<span class="line"><span style="color:#82AAFF;">print</span><span style="color:#89DDFF;">(</span><span style="color:#82AAFF;">dic</span><span style="color:#89DDFF;">)</span><span style="color:#A6ACCD;"> </span><span style="color:#676E95;font-style:italic;"># {&#39;id&#39;: 123, &#39;name&#39;: &#39;deeper&#39;, &#39;age&#39;: 24}</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># 方式二</span></span>
<span class="line"><span style="color:#A6ACCD;">dic</span><span style="color:#89DDFF;">[</span><span style="color:#89DDFF;">&#39;</span><span style="color:#C3E88D;">sign</span><span style="color:#89DDFF;">&#39;</span><span style="color:#89DDFF;">]</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">&#39;</span><span style="color:#C3E88D;">明日复明日，明日何其多!</span><span style="color:#89DDFF;">&#39;</span></span>
<span class="line"><span style="color:#82AAFF;">print</span><span style="color:#89DDFF;">(</span><span style="color:#82AAFF;">dic</span><span style="color:#89DDFF;">)</span><span style="color:#A6ACCD;"> </span><span style="color:#676E95;font-style:italic;"># {&#39;id&#39;: 123, &#39;name&#39;: &#39;deeper&#39;, &#39;age&#39;: 24, &#39;sign&#39;: &#39;明日复明日，明日何其多!&#39;}</span></span>
<span class="line"></span>
<span class="line"></span>
<span class="line"><span style="color:#89DDFF;font-style:italic;">&#39;&#39;&#39;</span><span style="color:#676E95;font-style:italic;">更新</span><span style="color:#89DDFF;font-style:italic;">&#39;&#39;&#39;</span></span>
<span class="line"><span style="color:#A6ACCD;">dic</span><span style="color:#89DDFF;">.</span><span style="color:#82AAFF;">update</span><span style="color:#89DDFF;">(</span><span style="color:#A6ACCD;font-style:italic;">name</span><span style="color:#89DDFF;">=</span><span style="color:#89DDFF;">&#39;</span><span style="color:#C3E88D;">macor</span><span style="color:#89DDFF;">&#39;</span><span style="color:#89DDFF;">)</span></span>
<span class="line"><span style="color:#82AAFF;">print</span><span style="color:#89DDFF;">(</span><span style="color:#82AAFF;">dic</span><span style="color:#89DDFF;">)</span><span style="color:#A6ACCD;"> </span><span style="color:#676E95;font-style:italic;"># {&#39;id&#39;: 123, &#39;name&#39;: &#39;macor&#39;, &#39;age&#39;: 24}</span></span>
<span class="line"></span>
<span class="line"></span>
<span class="line"><span style="color:#89DDFF;font-style:italic;">&#39;&#39;&#39;</span><span style="color:#676E95;font-style:italic;">删除</span><span style="color:#89DDFF;font-style:italic;">&#39;&#39;&#39;</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># 方式一</span></span>
<span class="line"><span style="color:#89DDFF;font-style:italic;">del</span><span style="color:#A6ACCD;"> dic</span><span style="color:#89DDFF;">[</span><span style="color:#89DDFF;">&#39;</span><span style="color:#C3E88D;">sign</span><span style="color:#89DDFF;">&#39;</span><span style="color:#89DDFF;">]</span></span>
<span class="line"><span style="color:#82AAFF;">print</span><span style="color:#89DDFF;">(</span><span style="color:#82AAFF;">dic</span><span style="color:#89DDFF;">)</span><span style="color:#A6ACCD;"> </span><span style="color:#676E95;font-style:italic;"># {&#39;id&#39;: 123, &#39;name&#39;: &#39;deeper&#39;, &#39;age&#39;: 24}</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># 方式二</span></span>
<span class="line"><span style="color:#A6ACCD;">age </span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;"> dic</span><span style="color:#89DDFF;">.</span><span style="color:#82AAFF;">pop</span><span style="color:#89DDFF;">(</span><span style="color:#89DDFF;">&#39;</span><span style="color:#C3E88D;">age</span><span style="color:#89DDFF;">&#39;</span><span style="color:#89DDFF;">)</span></span>
<span class="line"><span style="color:#82AAFF;">print</span><span style="color:#89DDFF;">(</span><span style="color:#82AAFF;">age</span><span style="color:#89DDFF;">)</span><span style="color:#A6ACCD;"> </span><span style="color:#676E95;font-style:italic;"># 24</span></span>
<span class="line"><span style="color:#82AAFF;">print</span><span style="color:#89DDFF;">(</span><span style="color:#82AAFF;">dic</span><span style="color:#89DDFF;">)</span><span style="color:#A6ACCD;"> </span><span style="color:#676E95;font-style:italic;"># {&#39;id&#39;: 123, &#39;name&#39;: &#39;deeper&#39;}</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># 方式三 随机删除一个</span></span>
<span class="line"><span style="color:#A6ACCD;">random </span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;"> dic</span><span style="color:#89DDFF;">.</span><span style="color:#82AAFF;">popitem</span><span style="color:#89DDFF;">()</span><span style="color:#A6ACCD;"> </span></span>
<span class="line"><span style="color:#82AAFF;">print</span><span style="color:#89DDFF;">(</span><span style="color:#82AAFF;">random</span><span style="color:#89DDFF;">)</span><span style="color:#A6ACCD;"> </span><span style="color:#676E95;font-style:italic;"># (&#39;name&#39;, &#39;deeper&#39;)</span></span>
<span class="line"><span style="color:#82AAFF;">print</span><span style="color:#89DDFF;">(</span><span style="color:#82AAFF;">dic</span><span style="color:#89DDFF;">)</span><span style="color:#A6ACCD;"> </span><span style="color:#676E95;font-style:italic;"># {&#39;id&#39;: 123}</span></span>
<span class="line"></span>
<span class="line"></span>
<span class="line"><span style="color:#89DDFF;font-style:italic;">&#39;&#39;&#39;</span><span style="color:#676E95;font-style:italic;">清空字典</span><span style="color:#89DDFF;font-style:italic;">&#39;&#39;&#39;</span></span>
<span class="line"><span style="color:#A6ACCD;">dic</span><span style="color:#89DDFF;">.</span><span style="color:#82AAFF;">clear</span><span style="color:#89DDFF;">()</span><span style="color:#676E95;font-style:italic;"># 清空字典，变量会被保留，可以进行打印</span></span>
<span class="line"><span style="color:#82AAFF;">print</span><span style="color:#89DDFF;">(</span><span style="color:#82AAFF;">dic</span><span style="color:#89DDFF;">)</span><span style="color:#A6ACCD;"> </span><span style="color:#676E95;font-style:italic;"># {}</span></span>
<span class="line"></span>
<span class="line"><span style="color:#89DDFF;font-style:italic;">del</span><span style="color:#A6ACCD;"> dic		 </span><span style="color:#676E95;font-style:italic;"># 该操作清空的字典，变量会被销毁，无法进行打印</span></span>
<span class="line"><span style="color:#82AAFF;">print</span><span style="color:#89DDFF;">(</span><span style="color:#82AAFF;">dic</span><span style="color:#89DDFF;">)</span><span style="color:#A6ACCD;"> </span><span style="color:#676E95;font-style:italic;"># 异常 NameError: name &#39;dic&#39; is not defined.</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br><span class="line-number">17</span><br><span class="line-number">18</span><br><span class="line-number">19</span><br><span class="line-number">20</span><br><span class="line-number">21</span><br><span class="line-number">22</span><br><span class="line-number">23</span><br><span class="line-number">24</span><br><span class="line-number">25</span><br><span class="line-number">26</span><br><span class="line-number">27</span><br><span class="line-number">28</span><br><span class="line-number">29</span><br><span class="line-number">30</span><br><span class="line-number">31</span><br><span class="line-number">32</span><br><span class="line-number">33</span><br><span class="line-number">34</span><br><span class="line-number">35</span><br><span class="line-number">36</span><br><span class="line-number">37</span><br><span class="line-number">38</span><br><span class="line-number">39</span><br><span class="line-number">40</span><br><span class="line-number">41</span><br><span class="line-number">42</span><br><span class="line-number">43</span><br></div></div><h2 id="合并字典" tabindex="-1">合并字典 <a class="header-anchor" href="#合并字典" aria-label="Permalink to &quot;合并字典&quot;">​</a></h2><div class="language-sh line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">sh</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#FFCB6B;">d1</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">=</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">{</span><span style="color:#89DDFF;">&#39;</span><span style="color:#C3E88D;">a</span><span style="color:#89DDFF;">&#39;</span><span style="color:#C3E88D;">:1}</span></span>
<span class="line"><span style="color:#FFCB6B;">d2</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">=</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">{</span><span style="color:#89DDFF;">&#39;</span><span style="color:#C3E88D;">b</span><span style="color:#89DDFF;">&#39;</span><span style="color:#C3E88D;">:2}</span></span>
<span class="line"></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># 方式一</span></span>
<span class="line"><span style="color:#FFCB6B;">nd</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">=</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">{</span><span style="color:#A6ACCD;">**</span><span style="color:#C3E88D;">d1,</span><span style="color:#A6ACCD;"> </span><span style="color:#A6ACCD;">**</span><span style="color:#C3E88D;">d2}</span></span>
<span class="line"></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># 方式二 - d1字典被改变了</span></span>
<span class="line"><span style="color:#FFCB6B;">d1.update(d2</span><span style="color:#A6ACCD;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># 方式三</span></span>
<span class="line"><span style="color:#FFCB6B;">nd</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">=</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">{}</span></span>
<span class="line"><span style="color:#FFCB6B;">nd.update(d1</span><span style="color:#A6ACCD;">)</span></span>
<span class="line"><span style="color:#FFCB6B;">nd.update(d2</span><span style="color:#A6ACCD;">)</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br></div></div><h2 id="判断是否是字典" tabindex="-1">判断是否是字典 <a class="header-anchor" href="#判断是否是字典" aria-label="Permalink to &quot;判断是否是字典&quot;">​</a></h2><div class="language-py line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">py</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#A6ACCD;">data </span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">{}</span></span>
<span class="line"><span style="color:#82AAFF;">print</span><span style="color:#89DDFF;">(</span><span style="color:#82AAFF;">isinstance</span><span style="color:#89DDFF;">(</span><span style="color:#82AAFF;">data</span><span style="color:#89DDFF;">,</span><span style="color:#FFCB6B;">dict</span><span style="color:#89DDFF;">))</span><span style="color:#A6ACCD;"> </span><span style="color:#676E95;font-style:italic;"># True</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br><span class="line-number">2</span><br></div></div><h2 id="判断是否为空" tabindex="-1">判断是否为空 <a class="header-anchor" href="#判断是否为空" aria-label="Permalink to &quot;判断是否为空&quot;">​</a></h2><div class="language-py line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">py</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#A6ACCD;">target </span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">{}</span><span style="color:#A6ACCD;"> </span><span style="color:#676E95;font-style:italic;"># 或 target = dict()</span></span>
<span class="line"><span style="color:#89DDFF;font-style:italic;">if</span><span style="color:#A6ACCD;"> target</span><span style="color:#89DDFF;">:</span></span>
<span class="line"><span style="color:#A6ACCD;">  </span><span style="color:#82AAFF;">print</span><span style="color:#89DDFF;">(</span><span style="color:#89DDFF;">&#39;</span><span style="color:#C3E88D;">target 字典不为空</span><span style="color:#89DDFF;">&#39;</span><span style="color:#89DDFF;">)</span></span>
<span class="line"><span style="color:#89DDFF;font-style:italic;">else</span><span style="color:#89DDFF;">:</span></span>
<span class="line"><span style="color:#A6ACCD;">  </span><span style="color:#82AAFF;">print</span><span style="color:#89DDFF;">(</span><span style="color:#89DDFF;">&#39;</span><span style="color:#C3E88D;">target 字典为空</span><span style="color:#89DDFF;">&#39;</span><span style="color:#89DDFF;">)</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># target 字典为空</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br></div></div><h2 id="三元表达式" tabindex="-1">三元表达式 <a class="header-anchor" href="#三元表达式" aria-label="Permalink to &quot;三元表达式&quot;">​</a></h2><div class="language-python line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">python</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#A6ACCD;">target </span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">{</span><span style="color:#89DDFF;">&quot;</span><span style="color:#C3E88D;">id</span><span style="color:#89DDFF;">&quot;</span><span style="color:#89DDFF;">:</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">&quot;</span><span style="color:#C3E88D;">221</span><span style="color:#89DDFF;">&quot;</span><span style="color:#89DDFF;">,</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">&quot;</span><span style="color:#C3E88D;">name</span><span style="color:#89DDFF;">&quot;</span><span style="color:#89DDFF;">:</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">&quot;</span><span style="color:#C3E88D;">deeper</span><span style="color:#89DDFF;">&quot;</span><span style="color:#89DDFF;">,</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">&quot;</span><span style="color:#C3E88D;">age</span><span style="color:#89DDFF;">&quot;</span><span style="color:#89DDFF;">:</span><span style="color:#A6ACCD;"> </span><span style="color:#F78C6C;">28</span><span style="color:#89DDFF;">}</span></span>
<span class="line"><span style="color:#A6ACCD;">sign </span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;"> target</span><span style="color:#89DDFF;">[</span><span style="color:#89DDFF;">&#39;</span><span style="color:#C3E88D;">sign</span><span style="color:#89DDFF;">&#39;</span><span style="color:#89DDFF;">]</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;font-style:italic;">if</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">&#39;</span><span style="color:#C3E88D;">sign</span><span style="color:#89DDFF;">&#39;</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">in</span><span style="color:#A6ACCD;"> target </span><span style="color:#89DDFF;font-style:italic;">else</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">&#39;</span><span style="color:#C3E88D;">暂无签名，什么信息也没有留下</span><span style="color:#89DDFF;">&#39;</span></span>
<span class="line"><span style="color:#82AAFF;">print</span><span style="color:#89DDFF;">(</span><span style="color:#82AAFF;">sign</span><span style="color:#89DDFF;">)</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># 暂无签名，什么信息也没有留下</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br></div></div><h2 id="字典中是否包含指定值" tabindex="-1">字典中是否包含指定值 <a class="header-anchor" href="#字典中是否包含指定值" aria-label="Permalink to &quot;字典中是否包含指定值&quot;">​</a></h2><div class="language-python line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">python</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#A6ACCD;">target </span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">{</span><span style="color:#89DDFF;">&quot;</span><span style="color:#C3E88D;">id</span><span style="color:#89DDFF;">&quot;</span><span style="color:#89DDFF;">:</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">&quot;</span><span style="color:#C3E88D;">221</span><span style="color:#89DDFF;">&quot;</span><span style="color:#89DDFF;">,</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">&quot;</span><span style="color:#C3E88D;">name</span><span style="color:#89DDFF;">&quot;</span><span style="color:#89DDFF;">:</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">&quot;</span><span style="color:#C3E88D;">deeper</span><span style="color:#89DDFF;">&quot;</span><span style="color:#89DDFF;">,</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">&quot;</span><span style="color:#C3E88D;">age</span><span style="color:#89DDFF;">&quot;</span><span style="color:#89DDFF;">:</span><span style="color:#A6ACCD;"> </span><span style="color:#F78C6C;">28</span><span style="color:#89DDFF;">}</span></span>
<span class="line"><span style="color:#89DDFF;font-style:italic;">if</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">&#39;</span><span style="color:#C3E88D;">deeper</span><span style="color:#89DDFF;">&#39;</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">in</span><span style="color:#A6ACCD;"> target</span><span style="color:#89DDFF;">[</span><span style="color:#89DDFF;">&#39;</span><span style="color:#C3E88D;">name</span><span style="color:#89DDFF;">&#39;</span><span style="color:#89DDFF;">]:</span></span>
<span class="line"><span style="color:#A6ACCD;">    </span><span style="color:#82AAFF;">print</span><span style="color:#89DDFF;">(</span><span style="color:#89DDFF;">&#39;</span><span style="color:#C3E88D;">deeper 用户存在</span><span style="color:#89DDFF;">&#39;</span><span style="color:#89DDFF;">)</span></span>
<span class="line"><span style="color:#89DDFF;font-style:italic;">else</span><span style="color:#89DDFF;">:</span></span>
<span class="line"><span style="color:#A6ACCD;">    </span><span style="color:#82AAFF;">print</span><span style="color:#89DDFF;">(</span><span style="color:#89DDFF;">&#39;</span><span style="color:#C3E88D;">deeper 用户不存在</span><span style="color:#89DDFF;">&#39;</span><span style="color:#89DDFF;">)</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># deeper 用户存在</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br></div></div><h2 id="字典遍历" tabindex="-1">字典遍历 <a class="header-anchor" href="#字典遍历" aria-label="Permalink to &quot;字典遍历&quot;">​</a></h2><div class="language-python line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">python</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#89DDFF;font-style:italic;">&#39;&#39;&#39;</span><span style="color:#676E95;font-style:italic;">1.字典取值</span><span style="color:#89DDFF;font-style:italic;">&#39;&#39;&#39;</span></span>
<span class="line"><span style="color:#A6ACCD;">target </span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">{</span><span style="color:#89DDFF;">&quot;</span><span style="color:#C3E88D;">id</span><span style="color:#89DDFF;">&quot;</span><span style="color:#89DDFF;">:</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">&quot;</span><span style="color:#C3E88D;">221</span><span style="color:#89DDFF;">&quot;</span><span style="color:#89DDFF;">,</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">&quot;</span><span style="color:#C3E88D;">name</span><span style="color:#89DDFF;">&quot;</span><span style="color:#89DDFF;">:</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">&quot;</span><span style="color:#C3E88D;">deeper</span><span style="color:#89DDFF;">&quot;</span><span style="color:#89DDFF;">,</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">&quot;</span><span style="color:#C3E88D;">age</span><span style="color:#89DDFF;">&quot;</span><span style="color:#89DDFF;">:</span><span style="color:#A6ACCD;"> </span><span style="color:#F78C6C;">28</span><span style="color:#89DDFF;">}</span></span>
<span class="line"><span style="color:#82AAFF;">print</span><span style="color:#89DDFF;">(</span><span style="color:#82AAFF;">target</span><span style="color:#89DDFF;">[</span><span style="color:#89DDFF;">&#39;</span><span style="color:#C3E88D;">id</span><span style="color:#89DDFF;">&#39;</span><span style="color:#89DDFF;">])</span><span style="color:#A6ACCD;">		</span><span style="color:#676E95;font-style:italic;"># 221</span></span>
<span class="line"><span style="color:#82AAFF;">print</span><span style="color:#89DDFF;">(</span><span style="color:#82AAFF;">target</span><span style="color:#89DDFF;">[</span><span style="color:#89DDFF;">&#39;</span><span style="color:#C3E88D;">name</span><span style="color:#89DDFF;">&#39;</span><span style="color:#89DDFF;">])</span><span style="color:#A6ACCD;"> </span><span style="color:#676E95;font-style:italic;"># deeper</span></span>
<span class="line"><span style="color:#82AAFF;">print</span><span style="color:#89DDFF;">(</span><span style="color:#82AAFF;">target</span><span style="color:#89DDFF;">[</span><span style="color:#89DDFF;">&#39;</span><span style="color:#C3E88D;">age</span><span style="color:#89DDFF;">&#39;</span><span style="color:#89DDFF;">])</span><span style="color:#A6ACCD;">  </span><span style="color:#676E95;font-style:italic;"># 28</span></span>
<span class="line"></span>
<span class="line"><span style="color:#89DDFF;font-style:italic;">&#39;&#39;&#39;</span><span style="color:#676E95;font-style:italic;">2.遍历字典的 键和值</span><span style="color:#89DDFF;font-style:italic;">&#39;&#39;&#39;</span></span>
<span class="line"><span style="color:#89DDFF;font-style:italic;">for</span><span style="color:#A6ACCD;"> name</span><span style="color:#89DDFF;">,</span><span style="color:#A6ACCD;">value </span><span style="color:#89DDFF;font-style:italic;">in</span><span style="color:#A6ACCD;"> target</span><span style="color:#89DDFF;">.</span><span style="color:#82AAFF;">items</span><span style="color:#89DDFF;">():</span></span>
<span class="line"><span style="color:#A6ACCD;">	</span><span style="color:#82AAFF;">print</span><span style="color:#89DDFF;">(</span><span style="color:#89DDFF;">&#39;</span><span style="color:#F78C6C;">{}</span><span style="color:#C3E88D;"> =&gt; </span><span style="color:#F78C6C;">{}</span><span style="color:#89DDFF;">&#39;</span><span style="color:#89DDFF;">.</span><span style="color:#82AAFF;">format</span><span style="color:#89DDFF;">(</span><span style="color:#82AAFF;">name</span><span style="color:#89DDFF;">,</span><span style="color:#82AAFF;"> value</span><span style="color:#89DDFF;">))</span><span style="color:#A6ACCD;"> 	</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># id =&gt; 221</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># name =&gt; deeper</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># age =&gt; 28</span></span>
<span class="line"></span>
<span class="line"><span style="color:#89DDFF;font-style:italic;">&#39;&#39;&#39;</span><span style="color:#676E95;font-style:italic;">3.遍历字典，获得元组</span><span style="color:#89DDFF;font-style:italic;">&#39;&#39;&#39;</span></span>
<span class="line"><span style="color:#89DDFF;font-style:italic;">for</span><span style="color:#A6ACCD;"> item </span><span style="color:#89DDFF;font-style:italic;">in</span><span style="color:#A6ACCD;"> target</span><span style="color:#89DDFF;">.</span><span style="color:#82AAFF;">items</span><span style="color:#89DDFF;">():</span></span>
<span class="line"><span style="color:#A6ACCD;">    </span><span style="color:#82AAFF;">print</span><span style="color:#89DDFF;">(</span><span style="color:#89DDFF;">&#39;</span><span style="color:#F78C6C;">{}</span><span style="color:#89DDFF;">&#39;</span><span style="color:#89DDFF;">.</span><span style="color:#82AAFF;">format</span><span style="color:#89DDFF;">(</span><span style="color:#82AAFF;">item</span><span style="color:#89DDFF;">))</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># (&#39;id&#39;, &#39;221&#39;)</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># (&#39;name&#39;, &#39;deeper&#39;)</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># (&#39;age&#39;, 28)</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br><span class="line-number">17</span><br><span class="line-number">18</span><br><span class="line-number">19</span><br></div></div><h2 id="🎉-list-声明一个列表" tabindex="-1">🎉 list 声明一个列表 <a class="header-anchor" href="#🎉-list-声明一个列表" aria-label="Permalink to &quot;🎉 list 声明一个列表&quot;">​</a></h2><div class="language-python line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">python</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#676E95;font-style:italic;"># 声明一个列表</span></span>
<span class="line"><span style="color:#A6ACCD;">lst </span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">[]</span><span style="color:#A6ACCD;"> 							</span><span style="color:#676E95;font-style:italic;"># 或 lst = list()</span></span>
<span class="line"><span style="color:#A6ACCD;">lst </span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">[</span><span style="color:#89DDFF;">&#39;</span><span style="color:#C3E88D;">a</span><span style="color:#89DDFF;">&#39;</span><span style="color:#89DDFF;">,</span><span style="color:#89DDFF;">&#39;</span><span style="color:#C3E88D;">b</span><span style="color:#89DDFF;">&#39;</span><span style="color:#89DDFF;">,</span><span style="color:#89DDFF;">&#39;</span><span style="color:#C3E88D;">c</span><span style="color:#89DDFF;">&#39;</span><span style="color:#89DDFF;">]</span><span style="color:#A6ACCD;"> 	</span><span style="color:#676E95;font-style:italic;"># 或 lst = list([&#39;a&#39;,&#39;b&#39;,&#39;c&#39;])</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br></div></div><h2 id="列表基本操作" tabindex="-1">列表基本操作 <a class="header-anchor" href="#列表基本操作" aria-label="Permalink to &quot;列表基本操作&quot;">​</a></h2><div class="language-python line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">python</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#676E95;font-style:italic;"># 初始数据</span></span>
<span class="line"><span style="color:#A6ACCD;">lst </span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">[</span></span>
<span class="line"><span style="color:#A6ACCD;">	  </span><span style="color:#89DDFF;">{</span><span style="color:#89DDFF;">&#39;</span><span style="color:#C3E88D;">id</span><span style="color:#89DDFF;">&#39;</span><span style="color:#89DDFF;">:</span><span style="color:#F78C6C;">1</span><span style="color:#89DDFF;">,</span><span style="color:#89DDFF;">&#39;</span><span style="color:#C3E88D;">name</span><span style="color:#89DDFF;">&#39;</span><span style="color:#89DDFF;">:</span><span style="color:#89DDFF;">&#39;</span><span style="color:#C3E88D;">bob</span><span style="color:#89DDFF;">&#39;</span><span style="color:#89DDFF;">,</span><span style="color:#89DDFF;">&#39;</span><span style="color:#C3E88D;">size</span><span style="color:#89DDFF;">&#39;</span><span style="color:#89DDFF;">:</span><span style="color:#F78C6C;">24</span><span style="color:#89DDFF;">},</span></span>
<span class="line"><span style="color:#A6ACCD;">    </span><span style="color:#89DDFF;">{</span><span style="color:#89DDFF;">&#39;</span><span style="color:#C3E88D;">id</span><span style="color:#89DDFF;">&#39;</span><span style="color:#89DDFF;">:</span><span style="color:#F78C6C;">2</span><span style="color:#89DDFF;">,</span><span style="color:#89DDFF;">&#39;</span><span style="color:#C3E88D;">name</span><span style="color:#89DDFF;">&#39;</span><span style="color:#89DDFF;">:</span><span style="color:#89DDFF;">&#39;</span><span style="color:#C3E88D;">bob</span><span style="color:#89DDFF;">&#39;</span><span style="color:#89DDFF;">,</span><span style="color:#89DDFF;">&#39;</span><span style="color:#C3E88D;">size</span><span style="color:#89DDFF;">&#39;</span><span style="color:#89DDFF;">:</span><span style="color:#F78C6C;">26</span><span style="color:#89DDFF;">},</span></span>
<span class="line"><span style="color:#89DDFF;">]</span></span>
<span class="line"></span>
<span class="line"><span style="color:#89DDFF;font-style:italic;">&#39;&#39;&#39;</span><span style="color:#676E95;font-style:italic;">追加一个字典</span><span style="color:#89DDFF;font-style:italic;">&#39;&#39;&#39;</span></span>
<span class="line"><span style="color:#A6ACCD;">lst</span><span style="color:#89DDFF;">.</span><span style="color:#82AAFF;">append</span><span style="color:#89DDFF;">({</span><span style="color:#89DDFF;">&#39;</span><span style="color:#C3E88D;">id</span><span style="color:#89DDFF;">&#39;</span><span style="color:#89DDFF;">:</span><span style="color:#82AAFF;"> </span><span style="color:#F78C6C;">3</span><span style="color:#89DDFF;">,</span><span style="color:#82AAFF;"> name</span><span style="color:#89DDFF;">:</span><span style="color:#82AAFF;"> </span><span style="color:#89DDFF;">&#39;</span><span style="color:#C3E88D;">tom</span><span style="color:#89DDFF;">&#39;</span><span style="color:#89DDFF;">,</span><span style="color:#82AAFF;"> </span><span style="color:#89DDFF;">&#39;</span><span style="color:#C3E88D;">age</span><span style="color:#89DDFF;">&#39;</span><span style="color:#89DDFF;">:</span><span style="color:#82AAFF;"> </span><span style="color:#F78C6C;">23</span><span style="color:#89DDFF;">})</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># [{&#39;id&#39;: 1, &#39;name&#39;: &#39;bob&#39;, &#39;age&#39;: 24}, {&#39;id&#39;: 2, &#39;name&#39;: &#39;bob&#39;, &#39;age&#39;: 26}, {&#39;id&#39;: 3, &#39;name&#39;: &#39;tom&#39;, &#39;age&#39;: 23}]</span></span>
<span class="line"></span>
<span class="line"></span>
<span class="line"><span style="color:#89DDFF;font-style:italic;">&#39;&#39;&#39;</span><span style="color:#676E95;font-style:italic;">取值  获取 tom 数据</span><span style="color:#89DDFF;font-style:italic;">&#39;&#39;&#39;</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># 利用索引 - (tom 的索引是2)</span></span>
<span class="line"><span style="color:#82AAFF;">print</span><span style="color:#89DDFF;">(</span><span style="color:#82AAFF;">lst</span><span style="color:#89DDFF;">[</span><span style="color:#F78C6C;">2</span><span style="color:#89DDFF;">])</span><span style="color:#A6ACCD;"> </span><span style="color:#676E95;font-style:italic;"># {&#39;id&#39;: 3, &#39;name&#39;: &#39;tom&#39;, &#39;age&#39;: 23}</span></span>
<span class="line"></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># 利用推导式 - 【返回单个对象】</span></span>
<span class="line"><span style="color:#A6ACCD;">user </span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">{</span><span style="color:#A6ACCD;"> k</span><span style="color:#89DDFF;">:</span><span style="color:#A6ACCD;"> v </span><span style="color:#89DDFF;font-style:italic;">for</span><span style="color:#A6ACCD;"> d </span><span style="color:#89DDFF;font-style:italic;">in</span><span style="color:#A6ACCD;"> lst </span><span style="color:#89DDFF;font-style:italic;">if</span><span style="color:#A6ACCD;"> d</span><span style="color:#89DDFF;">.</span><span style="color:#82AAFF;">get</span><span style="color:#89DDFF;">(</span><span style="color:#89DDFF;">&#39;</span><span style="color:#C3E88D;">name</span><span style="color:#89DDFF;">&#39;</span><span style="color:#89DDFF;">)</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">==</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">&#39;</span><span style="color:#C3E88D;">tom</span><span style="color:#89DDFF;">&#39;</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;font-style:italic;">for</span><span style="color:#A6ACCD;"> k</span><span style="color:#89DDFF;">,</span><span style="color:#A6ACCD;"> v </span><span style="color:#89DDFF;font-style:italic;">in</span><span style="color:#A6ACCD;"> d</span><span style="color:#89DDFF;">.</span><span style="color:#82AAFF;">items</span><span style="color:#89DDFF;">()</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">}</span></span>
<span class="line"><span style="color:#82AAFF;">print</span><span style="color:#89DDFF;">(</span><span style="color:#82AAFF;">user</span><span style="color:#89DDFF;">)</span><span style="color:#A6ACCD;"> </span><span style="color:#676E95;font-style:italic;"># {&#39;id&#39;: 3, &#39;name&#39;: &#39;tom&#39;, &#39;age&#39;: 23}</span></span>
<span class="line"></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># 利用推导式 - 【返回多条数据】获取 name=bob 的所有数据</span></span>
<span class="line"><span style="color:#A6ACCD;">users </span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">[</span><span style="color:#A6ACCD;"> d </span><span style="color:#89DDFF;font-style:italic;">for</span><span style="color:#A6ACCD;"> d </span><span style="color:#89DDFF;font-style:italic;">in</span><span style="color:#A6ACCD;"> lst </span><span style="color:#89DDFF;font-style:italic;">if</span><span style="color:#A6ACCD;"> d</span><span style="color:#89DDFF;">.</span><span style="color:#82AAFF;">get</span><span style="color:#89DDFF;">(</span><span style="color:#89DDFF;">&#39;</span><span style="color:#C3E88D;">name</span><span style="color:#89DDFF;">&#39;</span><span style="color:#89DDFF;">)</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">==</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">&#39;</span><span style="color:#C3E88D;">bob</span><span style="color:#89DDFF;">&#39;</span><span style="color:#89DDFF;">]</span></span>
<span class="line"><span style="color:#82AAFF;">print</span><span style="color:#89DDFF;">(</span><span style="color:#82AAFF;">users</span><span style="color:#89DDFF;">)</span><span style="color:#A6ACCD;"> </span><span style="color:#676E95;font-style:italic;"># [{&#39;id&#39;: 1, &#39;name&#39;: &#39;bob&#39;, &#39;age&#39;: 24}, {&#39;id&#39;: 2, &#39;name&#39;: &#39;bob&#39;, &#39;age&#39;: 26}]</span></span>
<span class="line"></span>
<span class="line"></span>
<span class="line"><span style="color:#89DDFF;font-style:italic;">&#39;&#39;&#39;</span><span style="color:#676E95;font-style:italic;">删除</span><span style="color:#89DDFF;font-style:italic;">&#39;&#39;&#39;</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># pop - 通过索引删除</span></span>
<span class="line"><span style="color:#A6ACCD;">end </span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;"> lst</span><span style="color:#89DDFF;">.</span><span style="color:#82AAFF;">pop</span><span style="color:#89DDFF;">()</span><span style="color:#A6ACCD;"> </span><span style="color:#676E95;font-style:italic;"># 或 lst.pop(2)</span></span>
<span class="line"><span style="color:#82AAFF;">print</span><span style="color:#89DDFF;">(</span><span style="color:#82AAFF;">end</span><span style="color:#89DDFF;">)</span><span style="color:#A6ACCD;"> </span><span style="color:#676E95;font-style:italic;"># {&#39;id&#39;: 3, &#39;name&#39;: &#39;tom&#39;, &#39;age&#39;: 23}</span></span>
<span class="line"><span style="color:#82AAFF;">print</span><span style="color:#89DDFF;">(</span><span style="color:#82AAFF;">lst</span><span style="color:#89DDFF;">)</span><span style="color:#A6ACCD;"> </span><span style="color:#676E95;font-style:italic;"># [{&#39;id&#39;: 1, &#39;name&#39;: &#39;bob&#39;, &#39;age&#39;: 24}, {&#39;id&#39;: 2, &#39;name&#39;: &#39;bob&#39;, &#39;age&#39;: 26}]</span></span>
<span class="line"></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># remove - 通过具体的值删除</span></span>
<span class="line"><span style="color:#A6ACCD;">lst</span><span style="color:#89DDFF;">.</span><span style="color:#82AAFF;">remove</span><span style="color:#89DDFF;">({</span><span style="color:#89DDFF;">&quot;</span><span style="color:#C3E88D;">id</span><span style="color:#89DDFF;">&quot;</span><span style="color:#89DDFF;">:</span><span style="color:#F78C6C;">3</span><span style="color:#89DDFF;">,</span><span style="color:#82AAFF;"> </span><span style="color:#89DDFF;">&quot;</span><span style="color:#C3E88D;">name</span><span style="color:#89DDFF;">&quot;</span><span style="color:#89DDFF;">:</span><span style="color:#89DDFF;">&quot;</span><span style="color:#C3E88D;">tom</span><span style="color:#89DDFF;">&quot;</span><span style="color:#89DDFF;">,</span><span style="color:#82AAFF;"> </span><span style="color:#89DDFF;">&quot;</span><span style="color:#C3E88D;">age</span><span style="color:#89DDFF;">&quot;</span><span style="color:#89DDFF;">:</span><span style="color:#F78C6C;">23</span><span style="color:#89DDFF;">})</span></span>
<span class="line"><span style="color:#82AAFF;">print</span><span style="color:#89DDFF;">(</span><span style="color:#82AAFF;">lst</span><span style="color:#89DDFF;">)</span><span style="color:#A6ACCD;"> </span><span style="color:#676E95;font-style:italic;">#[{&#39;id&#39;: 1, &#39;name&#39;: &#39;bob&#39;, &#39;age&#39;: 24}, {&#39;id&#39;: 2, &#39;name&#39;: &#39;bob&#39;, &#39;age&#39;: 26}]</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br><span class="line-number">17</span><br><span class="line-number">18</span><br><span class="line-number">19</span><br><span class="line-number">20</span><br><span class="line-number">21</span><br><span class="line-number">22</span><br><span class="line-number">23</span><br><span class="line-number">24</span><br><span class="line-number">25</span><br><span class="line-number">26</span><br><span class="line-number">27</span><br><span class="line-number">28</span><br><span class="line-number">29</span><br><span class="line-number">30</span><br><span class="line-number">31</span><br><span class="line-number">32</span><br><span class="line-number">33</span><br></div></div><blockquote><p><strong>注意</strong></p><p>如果我们不指定任何索引， <code>pop()</code> 删除并返回列表中的最后一个元素。</p></blockquote><h2 id="合并列表" tabindex="-1">合并列表 <a class="header-anchor" href="#合并列表" aria-label="Permalink to &quot;合并列表&quot;">​</a></h2><div class="language-python line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">python</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#A6ACCD;">lst </span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">[</span></span>
<span class="line"><span style="color:#A6ACCD;">    </span><span style="color:#89DDFF;">{</span><span style="color:#89DDFF;">&#39;</span><span style="color:#C3E88D;">id</span><span style="color:#89DDFF;">&#39;</span><span style="color:#89DDFF;">:</span><span style="color:#F78C6C;">1</span><span style="color:#89DDFF;">,</span><span style="color:#89DDFF;">&#39;</span><span style="color:#C3E88D;">name</span><span style="color:#89DDFF;">&#39;</span><span style="color:#89DDFF;">:</span><span style="color:#89DDFF;">&#39;</span><span style="color:#C3E88D;">bob</span><span style="color:#89DDFF;">&#39;</span><span style="color:#89DDFF;">,</span><span style="color:#89DDFF;">&#39;</span><span style="color:#C3E88D;">size</span><span style="color:#89DDFF;">&#39;</span><span style="color:#89DDFF;">:</span><span style="color:#F78C6C;">2</span><span style="color:#89DDFF;">},</span></span>
<span class="line"><span style="color:#A6ACCD;">    </span><span style="color:#89DDFF;">{</span><span style="color:#89DDFF;">&#39;</span><span style="color:#C3E88D;">id</span><span style="color:#89DDFF;">&#39;</span><span style="color:#89DDFF;">:</span><span style="color:#F78C6C;">2</span><span style="color:#89DDFF;">,</span><span style="color:#89DDFF;">&#39;</span><span style="color:#C3E88D;">name</span><span style="color:#89DDFF;">&#39;</span><span style="color:#89DDFF;">:</span><span style="color:#89DDFF;">&#39;</span><span style="color:#C3E88D;">bob</span><span style="color:#89DDFF;">&#39;</span><span style="color:#89DDFF;">,</span><span style="color:#89DDFF;">&#39;</span><span style="color:#C3E88D;">size</span><span style="color:#89DDFF;">&#39;</span><span style="color:#89DDFF;">:</span><span style="color:#F78C6C;">3</span><span style="color:#89DDFF;">},</span></span>
<span class="line"><span style="color:#A6ACCD;">    </span><span style="color:#89DDFF;">{</span><span style="color:#89DDFF;">&#39;</span><span style="color:#C3E88D;">id</span><span style="color:#89DDFF;">&#39;</span><span style="color:#89DDFF;">:</span><span style="color:#F78C6C;">3</span><span style="color:#89DDFF;">,</span><span style="color:#89DDFF;">&#39;</span><span style="color:#C3E88D;">name</span><span style="color:#89DDFF;">&#39;</span><span style="color:#89DDFF;">:</span><span style="color:#89DDFF;">&#39;</span><span style="color:#C3E88D;">sarah</span><span style="color:#89DDFF;">&#39;</span><span style="color:#89DDFF;">,</span><span style="color:#89DDFF;">&#39;</span><span style="color:#C3E88D;">size</span><span style="color:#89DDFF;">&#39;</span><span style="color:#89DDFF;">:</span><span style="color:#F78C6C;">2</span><span style="color:#89DDFF;">},</span></span>
<span class="line"><span style="color:#A6ACCD;">    </span><span style="color:#89DDFF;">{</span><span style="color:#89DDFF;">&#39;</span><span style="color:#C3E88D;">id</span><span style="color:#89DDFF;">&#39;</span><span style="color:#89DDFF;">:</span><span style="color:#F78C6C;">4</span><span style="color:#89DDFF;">,</span><span style="color:#89DDFF;">&#39;</span><span style="color:#C3E88D;">name</span><span style="color:#89DDFF;">&#39;</span><span style="color:#89DDFF;">:</span><span style="color:#89DDFF;">&#39;</span><span style="color:#C3E88D;">sarah</span><span style="color:#89DDFF;">&#39;</span><span style="color:#89DDFF;">,</span><span style="color:#89DDFF;">&#39;</span><span style="color:#C3E88D;">size</span><span style="color:#89DDFF;">&#39;</span><span style="color:#89DDFF;">:</span><span style="color:#F78C6C;">2</span><span style="color:#89DDFF;">}</span></span>
<span class="line"><span style="color:#89DDFF;">]</span></span>
<span class="line"><span style="color:#A6ACCD;">newlst </span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">[</span></span>
<span class="line"><span style="color:#A6ACCD;">    </span><span style="color:#89DDFF;">{</span><span style="color:#89DDFF;">&#39;</span><span style="color:#C3E88D;">id</span><span style="color:#89DDFF;">&#39;</span><span style="color:#89DDFF;">:</span><span style="color:#F78C6C;">5</span><span style="color:#89DDFF;">,</span><span style="color:#89DDFF;">&#39;</span><span style="color:#C3E88D;">name</span><span style="color:#89DDFF;">&#39;</span><span style="color:#89DDFF;">:</span><span style="color:#89DDFF;">&#39;</span><span style="color:#C3E88D;">sarah</span><span style="color:#89DDFF;">&#39;</span><span style="color:#89DDFF;">,</span><span style="color:#89DDFF;">&#39;</span><span style="color:#C3E88D;">size</span><span style="color:#89DDFF;">&#39;</span><span style="color:#89DDFF;">:</span><span style="color:#F78C6C;">3</span><span style="color:#89DDFF;">},</span></span>
<span class="line"><span style="color:#A6ACCD;">    </span><span style="color:#89DDFF;">{</span><span style="color:#89DDFF;">&#39;</span><span style="color:#C3E88D;">id</span><span style="color:#89DDFF;">&#39;</span><span style="color:#89DDFF;">:</span><span style="color:#F78C6C;">6</span><span style="color:#89DDFF;">,</span><span style="color:#89DDFF;">&#39;</span><span style="color:#C3E88D;">name</span><span style="color:#89DDFF;">&#39;</span><span style="color:#89DDFF;">:</span><span style="color:#89DDFF;">&#39;</span><span style="color:#C3E88D;">sarah</span><span style="color:#89DDFF;">&#39;</span><span style="color:#89DDFF;">,</span><span style="color:#89DDFF;">&#39;</span><span style="color:#C3E88D;">size</span><span style="color:#89DDFF;">&#39;</span><span style="color:#89DDFF;">:</span><span style="color:#F78C6C;">3</span><span style="color:#89DDFF;">},</span></span>
<span class="line"><span style="color:#A6ACCD;">    </span><span style="color:#89DDFF;">{</span><span style="color:#89DDFF;">&#39;</span><span style="color:#C3E88D;">id</span><span style="color:#89DDFF;">&#39;</span><span style="color:#89DDFF;">:</span><span style="color:#F78C6C;">7</span><span style="color:#89DDFF;">,</span><span style="color:#89DDFF;">&#39;</span><span style="color:#C3E88D;">name</span><span style="color:#89DDFF;">&#39;</span><span style="color:#89DDFF;">:</span><span style="color:#89DDFF;">&#39;</span><span style="color:#C3E88D;">jack</span><span style="color:#89DDFF;">&#39;</span><span style="color:#89DDFF;">,</span><span style="color:#89DDFF;">&#39;</span><span style="color:#C3E88D;">size</span><span style="color:#89DDFF;">&#39;</span><span style="color:#89DDFF;">:</span><span style="color:#F78C6C;">5</span><span style="color:#89DDFF;">}</span></span>
<span class="line"><span style="color:#89DDFF;">]</span></span>
<span class="line"></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># 方式一</span></span>
<span class="line"><span style="color:#A6ACCD;">lst</span><span style="color:#89DDFF;">.</span><span style="color:#82AAFF;">extend</span><span style="color:#89DDFF;">(</span><span style="color:#82AAFF;">newlst</span><span style="color:#89DDFF;">)</span></span>
<span class="line"><span style="color:#A6ACCD;">ids </span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">[</span><span style="color:#A6ACCD;"> item</span><span style="color:#89DDFF;">[</span><span style="color:#89DDFF;">&#39;</span><span style="color:#C3E88D;">id</span><span style="color:#89DDFF;">&#39;</span><span style="color:#89DDFF;">]</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;font-style:italic;">for</span><span style="color:#A6ACCD;"> item </span><span style="color:#89DDFF;font-style:italic;">in</span><span style="color:#A6ACCD;"> lst </span><span style="color:#89DDFF;">]</span></span>
<span class="line"><span style="color:#82AAFF;">print</span><span style="color:#89DDFF;">(</span><span style="color:#82AAFF;">ids</span><span style="color:#89DDFF;">)</span><span style="color:#A6ACCD;"> </span><span style="color:#676E95;font-style:italic;"># 7个ID [1,2,3,4,5,6,7]</span></span>
<span class="line"></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># 方式二</span></span>
<span class="line"><span style="color:#A6ACCD;">res </span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;"> lst </span><span style="color:#89DDFF;">+</span><span style="color:#A6ACCD;"> newlst</span></span>
<span class="line"><span style="color:#A6ACCD;">names </span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">[</span><span style="color:#A6ACCD;"> item</span><span style="color:#89DDFF;">[</span><span style="color:#89DDFF;">&#39;</span><span style="color:#C3E88D;">name</span><span style="color:#89DDFF;">&#39;</span><span style="color:#89DDFF;">]</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;font-style:italic;">for</span><span style="color:#A6ACCD;"> res </span><span style="color:#89DDFF;font-style:italic;">in</span><span style="color:#A6ACCD;"> res </span><span style="color:#89DDFF;">]</span></span>
<span class="line"><span style="color:#82AAFF;">print</span><span style="color:#89DDFF;">(</span><span style="color:#82AAFF;">names</span><span style="color:#89DDFF;">)</span><span style="color:#A6ACCD;"> </span><span style="color:#676E95;font-style:italic;"># 依然是7个 [&#39;bob&#39;, &#39;bob&#39;, &#39;sarah&#39;, &#39;sarah&#39;, &#39;sarah&#39;, &#39;sarah&#39;, &#39;jack&#39;]</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br><span class="line-number">17</span><br><span class="line-number">18</span><br><span class="line-number">19</span><br><span class="line-number">20</span><br><span class="line-number">21</span><br></div></div><blockquote><p>此示例中，打印的<code>ids</code>, <code>names</code>的获取，利用了 Python 的<code>推导式特性</code></p></blockquote><h2 id="判断列表是否为空" tabindex="-1">判断列表是否为空 <a class="header-anchor" href="#判断列表是否为空" aria-label="Permalink to &quot;判断列表是否为空&quot;">​</a></h2><div class="language-python line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">python</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#A6ACCD;">target </span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">[]</span><span style="color:#A6ACCD;"> </span><span style="color:#676E95;font-style:italic;"># 或 target = list()</span></span>
<span class="line"><span style="color:#89DDFF;font-style:italic;">if</span><span style="color:#A6ACCD;"> target</span><span style="color:#89DDFF;">:</span></span>
<span class="line"><span style="color:#A6ACCD;">    </span><span style="color:#82AAFF;">print</span><span style="color:#89DDFF;">(</span><span style="color:#89DDFF;">&#39;</span><span style="color:#C3E88D;">target 列表不为空</span><span style="color:#89DDFF;">&#39;</span><span style="color:#89DDFF;">)</span></span>
<span class="line"><span style="color:#89DDFF;font-style:italic;">else</span><span style="color:#89DDFF;">:</span></span>
<span class="line"><span style="color:#A6ACCD;">    </span><span style="color:#82AAFF;">print</span><span style="color:#89DDFF;">(</span><span style="color:#89DDFF;">&#39;</span><span style="color:#C3E88D;">target 列表为空</span><span style="color:#89DDFF;">&#39;</span><span style="color:#89DDFF;">)</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># target 列表为空</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br></div></div><h2 id="统计重复元素" tabindex="-1">统计重复元素 <a class="header-anchor" href="#统计重复元素" aria-label="Permalink to &quot;统计重复元素&quot;">​</a></h2><div class="language-python line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">python</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#A6ACCD;">lst </span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">[</span><span style="color:#F78C6C;">0</span><span style="color:#89DDFF;">,</span><span style="color:#F78C6C;">3</span><span style="color:#89DDFF;">,</span><span style="color:#F78C6C;">6</span><span style="color:#89DDFF;">,</span><span style="color:#F78C6C;">1</span><span style="color:#89DDFF;">,</span><span style="color:#F78C6C;">4</span><span style="color:#89DDFF;">,</span><span style="color:#F78C6C;">7</span><span style="color:#89DDFF;">,</span><span style="color:#F78C6C;">2</span><span style="color:#89DDFF;">,</span><span style="color:#F78C6C;">5</span><span style="color:#89DDFF;">,</span><span style="color:#F78C6C;">8</span><span style="color:#89DDFF;">,</span><span style="color:#F78C6C;">3</span><span style="color:#89DDFF;">,</span><span style="color:#F78C6C;">6</span><span style="color:#89DDFF;">,</span><span style="color:#F78C6C;">9</span><span style="color:#89DDFF;">,</span><span style="color:#F78C6C;">4</span><span style="color:#89DDFF;">,</span><span style="color:#F78C6C;">7</span><span style="color:#89DDFF;">,</span><span style="color:#F78C6C;">10</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">]</span></span>
<span class="line"><span style="color:#82AAFF;">print</span><span style="color:#89DDFF;">(</span><span style="color:#82AAFF;">sorted</span><span style="color:#89DDFF;">(</span><span style="color:#82AAFF;">lst</span><span style="color:#89DDFF;">))</span></span>
<span class="line"></span>
<span class="line"><span style="color:#89DDFF;font-style:italic;">from</span><span style="color:#A6ACCD;"> collections </span><span style="color:#89DDFF;font-style:italic;">import</span><span style="color:#A6ACCD;"> Counter</span></span>
<span class="line"><span style="color:#A6ACCD;">arr </span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;"> </span><span style="color:#FFCB6B;">dict</span><span style="color:#89DDFF;">(</span><span style="color:#82AAFF;">Counter</span><span style="color:#89DDFF;">(</span><span style="color:#82AAFF;">lst</span><span style="color:#89DDFF;">))</span></span>
<span class="line"><span style="color:#82AAFF;">print</span><span style="color:#89DDFF;">(</span><span style="color:#82AAFF;">arr</span><span style="color:#89DDFF;">)</span></span>
<span class="line"><span style="color:#82AAFF;">print</span><span style="color:#89DDFF;">([</span><span style="color:#82AAFF;">key </span><span style="color:#89DDFF;font-style:italic;">for</span><span style="color:#82AAFF;"> key</span><span style="color:#89DDFF;">,</span><span style="color:#82AAFF;">value </span><span style="color:#89DDFF;font-style:italic;">in</span><span style="color:#82AAFF;"> arr</span><span style="color:#89DDFF;">.</span><span style="color:#82AAFF;">items</span><span style="color:#89DDFF;">()</span><span style="color:#82AAFF;"> </span><span style="color:#89DDFF;font-style:italic;">if</span><span style="color:#82AAFF;"> value </span><span style="color:#89DDFF;">&gt;</span><span style="color:#82AAFF;"> </span><span style="color:#F78C6C;">1</span><span style="color:#89DDFF;">])</span></span>
<span class="line"><span style="color:#82AAFF;">print</span><span style="color:#89DDFF;">({</span><span style="color:#82AAFF;">key</span><span style="color:#89DDFF;">:</span><span style="color:#82AAFF;"> value </span><span style="color:#89DDFF;font-style:italic;">for</span><span style="color:#82AAFF;"> key</span><span style="color:#89DDFF;">,</span><span style="color:#82AAFF;">value </span><span style="color:#89DDFF;font-style:italic;">in</span><span style="color:#82AAFF;"> arr</span><span style="color:#89DDFF;">.</span><span style="color:#82AAFF;">items</span><span style="color:#89DDFF;">()</span><span style="color:#82AAFF;"> </span><span style="color:#89DDFF;font-style:italic;">if</span><span style="color:#82AAFF;"> value </span><span style="color:#89DDFF;">&gt;</span><span style="color:#82AAFF;"> </span><span style="color:#F78C6C;">1</span><span style="color:#89DDFF;">})</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br></div></div><h2 id="for-循环" tabindex="-1">For 循环 <a class="header-anchor" href="#for-循环" aria-label="Permalink to &quot;For 循环&quot;">​</a></h2><div class="language-python line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">python</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#A6ACCD;">field </span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">[[</span><span style="color:#F78C6C;">1</span><span style="color:#89DDFF;">,</span><span style="color:#F78C6C;">2</span><span style="color:#89DDFF;">],[</span><span style="color:#F78C6C;">3</span><span style="color:#89DDFF;">,</span><span style="color:#F78C6C;">4</span><span style="color:#89DDFF;">],[</span><span style="color:#F78C6C;">5</span><span style="color:#89DDFF;">,</span><span style="color:#F78C6C;">6</span><span style="color:#89DDFF;">]]</span></span>
<span class="line"></span>
<span class="line"><span style="color:#89DDFF;font-style:italic;">for</span><span style="color:#A6ACCD;"> idx</span><span style="color:#89DDFF;">,</span><span style="color:#A6ACCD;"> i </span><span style="color:#89DDFF;font-style:italic;">in</span><span style="color:#A6ACCD;"> </span><span style="color:#82AAFF;">enumerate</span><span style="color:#89DDFF;">(</span><span style="color:#82AAFF;">field</span><span style="color:#89DDFF;">):</span></span>
<span class="line"><span style="color:#A6ACCD;">    </span><span style="color:#82AAFF;">print</span><span style="color:#89DDFF;">(</span><span style="color:#82AAFF;">idx</span><span style="color:#89DDFF;">,</span><span style="color:#82AAFF;"> i</span><span style="color:#89DDFF;">,</span><span style="color:#82AAFF;"> i</span><span style="color:#89DDFF;">[</span><span style="color:#F78C6C;">0</span><span style="color:#89DDFF;">],</span><span style="color:#82AAFF;"> i</span><span style="color:#89DDFF;">[</span><span style="color:#F78C6C;">1</span><span style="color:#89DDFF;">])</span><span style="color:#A6ACCD;">;</span></span>
<span class="line"><span style="color:#A6ACCD;">    </span><span style="color:#89DDFF;font-style:italic;">pass</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br></div></div><h2 id="append-将元素追加到列表末尾" tabindex="-1">append() - 将元素追加到列表末尾 <a class="header-anchor" href="#append-将元素追加到列表末尾" aria-label="Permalink to &quot;append() - 将元素追加到列表末尾&quot;">​</a></h2><div class="language-python line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">python</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#A6ACCD;">a </span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">[</span><span style="color:#F78C6C;">1</span><span style="color:#89DDFF;">,</span><span style="color:#A6ACCD;"> </span><span style="color:#F78C6C;">2</span><span style="color:#89DDFF;">,</span><span style="color:#A6ACCD;"> </span><span style="color:#F78C6C;">3</span><span style="color:#89DDFF;">]</span></span>
<span class="line"><span style="color:#A6ACCD;">a</span><span style="color:#89DDFF;">.</span><span style="color:#82AAFF;">append</span><span style="color:#89DDFF;">(</span><span style="color:#F78C6C;">6</span><span style="color:#89DDFF;">,</span><span style="color:#82AAFF;"> </span><span style="color:#F78C6C;">7</span><span style="color:#89DDFF;">)</span></span>
<span class="line"><span style="color:#82AAFF;">print</span><span style="color:#89DDFF;">(</span><span style="color:#82AAFF;">a</span><span style="color:#89DDFF;">)</span><span style="color:#A6ACCD;"> </span><span style="color:#676E95;font-style:italic;"># [1,2,3,6,7]</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br></div></div><h2 id="extend-将一个列表中的数据逐一追加到指定列表中" tabindex="-1">extend() - 将一个列表中的数据<code>逐一</code>追加到指定列表中 <a class="header-anchor" href="#extend-将一个列表中的数据逐一追加到指定列表中" aria-label="Permalink to &quot;extend() - 将一个列表中的数据`逐一`追加到指定列表中&quot;">​</a></h2><div class="language-python line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">python</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#A6ACCD;">a </span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">[</span><span style="color:#F78C6C;">1</span><span style="color:#89DDFF;">,</span><span style="color:#F78C6C;">2</span><span style="color:#89DDFF;">]</span></span>
<span class="line"><span style="color:#A6ACCD;">b </span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">[</span><span style="color:#F78C6C;">3</span><span style="color:#89DDFF;">,</span><span style="color:#F78C6C;">4</span><span style="color:#89DDFF;">]</span></span>
<span class="line"><span style="color:#A6ACCD;">c </span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">[</span><span style="color:#F78C6C;">11</span><span style="color:#89DDFF;">,</span><span style="color:#F78C6C;">22</span><span style="color:#89DDFF;">]</span></span>
<span class="line"></span>
<span class="line"><span style="color:#A6ACCD;">a</span><span style="color:#89DDFF;">.</span><span style="color:#82AAFF;">append</span><span style="color:#89DDFF;">(</span><span style="color:#82AAFF;">c</span><span style="color:#89DDFF;">)</span></span>
<span class="line"><span style="color:#82AAFF;">print</span><span style="color:#89DDFF;">(</span><span style="color:#82AAFF;">a</span><span style="color:#89DDFF;">)</span><span style="color:#A6ACCD;">	</span><span style="color:#676E95;font-style:italic;"># [1,2,[11,22]]</span></span>
<span class="line"></span>
<span class="line"><span style="color:#A6ACCD;">b</span><span style="color:#89DDFF;">.</span><span style="color:#82AAFF;">extend</span><span style="color:#89DDFF;">(</span><span style="color:#82AAFF;">c</span><span style="color:#89DDFF;">)</span></span>
<span class="line"><span style="color:#82AAFF;">print</span><span style="color:#89DDFF;">(</span><span style="color:#82AAFF;">b</span><span style="color:#89DDFF;">)</span><span style="color:#A6ACCD;">	</span><span style="color:#676E95;font-style:italic;"># [3,4,11,22]</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br></div></div><h2 id="insert-index-value-将新元素添加到指定索引号前面" tabindex="-1">insert(index, value) - 将新元素添加到指定索引号前面 <a class="header-anchor" href="#insert-index-value-将新元素添加到指定索引号前面" aria-label="Permalink to &quot;insert(index, value) - 将新元素添加到指定索引号前面&quot;">​</a></h2><div class="language-python line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">python</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#A6ACCD;">a </span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">[</span><span style="color:#F78C6C;">2</span><span style="color:#89DDFF;">,</span><span style="color:#F78C6C;">3</span><span style="color:#89DDFF;">,</span><span style="color:#F78C6C;">5</span><span style="color:#89DDFF;">]</span></span>
<span class="line"><span style="color:#A6ACCD;">a</span><span style="color:#89DDFF;">.</span><span style="color:#82AAFF;">insert</span><span style="color:#89DDFF;">(</span><span style="color:#F78C6C;">0</span><span style="color:#89DDFF;">,</span><span style="color:#82AAFF;"> </span><span style="color:#F78C6C;">1</span><span style="color:#89DDFF;">)</span></span>
<span class="line"><span style="color:#82AAFF;">print</span><span style="color:#89DDFF;">(</span><span style="color:#82AAFF;">a</span><span style="color:#89DDFF;">)</span><span style="color:#A6ACCD;">	</span><span style="color:#676E95;font-style:italic;"># [1,2,3,5]</span></span>
<span class="line"></span>
<span class="line"><span style="color:#A6ACCD;">a</span><span style="color:#89DDFF;">.</span><span style="color:#82AAFF;">insert</span><span style="color:#89DDFF;">(-</span><span style="color:#F78C6C;">1</span><span style="color:#89DDFF;">,</span><span style="color:#82AAFF;"> </span><span style="color:#F78C6C;">4</span><span style="color:#89DDFF;">)</span><span style="color:#A6ACCD;"> </span><span style="color:#676E95;font-style:italic;"># 或者 a.insert(3, 4)</span></span>
<span class="line"><span style="color:#82AAFF;">print</span><span style="color:#89DDFF;">(</span><span style="color:#82AAFF;">a</span><span style="color:#89DDFF;">)</span><span style="color:#A6ACCD;">	</span><span style="color:#676E95;font-style:italic;"># [1,2,3,4,5]</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br></div></div><h2 id="🎉-tuple-元组" tabindex="-1">🎉 tuple - 元组 <a class="header-anchor" href="#🎉-tuple-元组" aria-label="Permalink to &quot;🎉 tuple - 元组&quot;">​</a></h2><p>格式 - (n,)</p><div class="language-python line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">python</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#A6ACCD;">tup </span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">()</span><span style="color:#A6ACCD;"> </span><span style="color:#676E95;font-style:italic;"># 或 tup = tuple()</span></span>
<span class="line"><span style="color:#A6ACCD;">tup </span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">(</span><span style="color:#F78C6C;">1</span><span style="color:#89DDFF;">,)</span><span style="color:#A6ACCD;"> </span><span style="color:#676E95;font-style:italic;"># 或 tup = tuple(1,)</span></span>
<span class="line"><span style="color:#A6ACCD;">tup </span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">(</span><span style="color:#F78C6C;">1</span><span style="color:#89DDFF;">,</span><span style="color:#F78C6C;">2</span><span style="color:#89DDFF;">,</span><span style="color:#F78C6C;">3</span><span style="color:#89DDFF;">,</span><span style="color:#89DDFF;">&#39;</span><span style="color:#C3E88D;">a</span><span style="color:#89DDFF;">&#39;</span><span style="color:#89DDFF;">)</span><span style="color:#A6ACCD;"> </span><span style="color:#676E95;font-style:italic;"># 或 tup = tuple(1,2,3,&#39;a&#39;)</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br></div></div><blockquote><p><strong>注意</strong></p><p>一个参数时，建议在结尾添加一个英文逗号</p></blockquote><h2 id="函数传参" tabindex="-1">函数传参 <a class="header-anchor" href="#函数传参" aria-label="Permalink to &quot;函数传参&quot;">​</a></h2><blockquote><p><strong>Python 有两种多值参数</strong></p><ol><li>参数名前增加一个*可以接收元组 ( *args )</li><li>参数名前增加两个*可以接收字典 ( **kwargs )</li></ol></blockquote><h2 id="多值参数" tabindex="-1">多值参数 <a class="header-anchor" href="#多值参数" aria-label="Permalink to &quot;多值参数&quot;">​</a></h2><div class="language-python line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">python</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#C792EA;">def</span><span style="color:#A6ACCD;"> </span><span style="color:#82AAFF;">demo</span><span style="color:#89DDFF;">(</span><span style="color:#A6ACCD;font-style:italic;">number</span><span style="color:#89DDFF;">,</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">*</span><span style="color:#A6ACCD;font-style:italic;">args</span><span style="color:#89DDFF;">,</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">**</span><span style="color:#A6ACCD;font-style:italic;">kwargs</span><span style="color:#89DDFF;">):</span></span>
<span class="line"><span style="color:#A6ACCD;">  	</span><span style="color:#82AAFF;">print</span><span style="color:#89DDFF;">(</span><span style="color:#82AAFF;">number</span><span style="color:#89DDFF;">)</span></span>
<span class="line"><span style="color:#A6ACCD;">  	</span><span style="color:#82AAFF;">print</span><span style="color:#89DDFF;">(</span><span style="color:#82AAFF;">args</span><span style="color:#89DDFF;">)</span></span>
<span class="line"><span style="color:#A6ACCD;">  	</span><span style="color:#82AAFF;">print</span><span style="color:#89DDFF;">(</span><span style="color:#82AAFF;">kwargs</span><span style="color:#89DDFF;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#82AAFF;">demo</span><span style="color:#89DDFF;">(</span><span style="color:#F78C6C;">1</span><span style="color:#89DDFF;">)</span><span style="color:#A6ACCD;"> </span><span style="color:#676E95;font-style:italic;"># 1 | () | {}</span></span>
<span class="line"><span style="color:#82AAFF;">demo</span><span style="color:#89DDFF;">(</span><span style="color:#F78C6C;">1</span><span style="color:#89DDFF;">,</span><span style="color:#F78C6C;">2</span><span style="color:#89DDFF;">,</span><span style="color:#F78C6C;">3</span><span style="color:#89DDFF;">,</span><span style="color:#F78C6C;">4</span><span style="color:#89DDFF;">)</span><span style="color:#A6ACCD;"> 	</span><span style="color:#676E95;font-style:italic;"># 1 | (2,3,4) 	| {}</span></span>
<span class="line"><span style="color:#82AAFF;">demo</span><span style="color:#89DDFF;">(</span><span style="color:#F78C6C;">1</span><span style="color:#89DDFF;">,</span><span style="color:#F78C6C;">2</span><span style="color:#89DDFF;">,</span><span style="color:#F78C6C;">3</span><span style="color:#89DDFF;">,</span><span style="color:#F78C6C;">4</span><span style="color:#89DDFF;">,</span><span style="color:#A6ACCD;font-style:italic;">name</span><span style="color:#89DDFF;">=</span><span style="color:#89DDFF;">&#39;</span><span style="color:#C3E88D;">deeper</span><span style="color:#89DDFF;">&#39;</span><span style="color:#89DDFF;">,</span><span style="color:#82AAFF;"> </span><span style="color:#A6ACCD;font-style:italic;">age</span><span style="color:#89DDFF;">=</span><span style="color:#F78C6C;">24</span><span style="color:#89DDFF;">)</span><span style="color:#A6ACCD;">		</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># 1 | (2,3,4)   | {&#39;name&#39;: &#39;deeper&#39;, &#39;age&#39;: 24}</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br></div></div><h2 id="数字累加案例" tabindex="-1">数字累加案例 <a class="header-anchor" href="#数字累加案例" aria-label="Permalink to &quot;数字累加案例&quot;">​</a></h2><div class="language-python line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">python</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#C792EA;">def</span><span style="color:#A6ACCD;"> </span><span style="color:#82AAFF;">sum_numbers</span><span style="color:#89DDFF;">(*</span><span style="color:#A6ACCD;font-style:italic;">args</span><span style="color:#89DDFF;">):</span></span>
<span class="line"><span style="color:#A6ACCD;">    num </span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;"> </span><span style="color:#F78C6C;">0</span></span>
<span class="line"><span style="color:#A6ACCD;">    </span><span style="color:#89DDFF;font-style:italic;">for</span><span style="color:#A6ACCD;"> n </span><span style="color:#89DDFF;font-style:italic;">in</span><span style="color:#A6ACCD;"> args</span><span style="color:#89DDFF;">:</span></span>
<span class="line"><span style="color:#A6ACCD;">        num </span><span style="color:#89DDFF;">+=</span><span style="color:#A6ACCD;"> n</span></span>
<span class="line"><span style="color:#A6ACCD;">    </span><span style="color:#89DDFF;font-style:italic;">return</span><span style="color:#A6ACCD;"> num</span></span>
<span class="line"></span>
<span class="line"><span style="color:#82AAFF;">print</span><span style="color:#89DDFF;">(</span><span style="color:#82AAFF;">sum_numbers</span><span style="color:#89DDFF;">(</span><span style="color:#F78C6C;">1</span><span style="color:#89DDFF;">,</span><span style="color:#F78C6C;">2</span><span style="color:#89DDFF;">,</span><span style="color:#F78C6C;">3</span><span style="color:#89DDFF;">,</span><span style="color:#F78C6C;">4</span><span style="color:#89DDFF;">))</span><span style="color:#A6ACCD;"> </span><span style="color:#676E95;font-style:italic;"># num = 10</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br></div></div><h2 id="元组和字典的拆包" tabindex="-1">元组和字典的拆包 <a class="header-anchor" href="#元组和字典的拆包" aria-label="Permalink to &quot;元组和字典的拆包&quot;">​</a></h2><blockquote><p>前面我们提到过：</p><p><code>*args</code> 接收一个<code>元组</code>数据</p><p><code>**kwargs</code>接收一个键和值的<code>字典</code>数据</p></blockquote><div class="language-python line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">python</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#C792EA;">def</span><span style="color:#A6ACCD;"> </span><span style="color:#82AAFF;">demo</span><span style="color:#89DDFF;">(*</span><span style="color:#A6ACCD;font-style:italic;">args</span><span style="color:#89DDFF;">,</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">**</span><span style="color:#A6ACCD;font-style:italic;">kwargs</span><span style="color:#89DDFF;">):</span></span>
<span class="line"><span style="color:#A6ACCD;">    </span><span style="color:#82AAFF;">print</span><span style="color:#89DDFF;">(</span><span style="color:#89DDFF;">&#39;</span><span style="color:#C3E88D;">args =&gt;</span><span style="color:#89DDFF;">&#39;</span><span style="color:#89DDFF;">,</span><span style="color:#82AAFF;"> args</span><span style="color:#89DDFF;">)</span></span>
<span class="line"><span style="color:#A6ACCD;">    </span><span style="color:#82AAFF;">print</span><span style="color:#89DDFF;">(</span><span style="color:#89DDFF;">&#39;</span><span style="color:#C3E88D;">kwargs =&gt;</span><span style="color:#89DDFF;">&#39;</span><span style="color:#89DDFF;">,</span><span style="color:#82AAFF;"> kwargs</span><span style="color:#89DDFF;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#A6ACCD;">gl_nums </span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">(</span><span style="color:#F78C6C;">1</span><span style="color:#89DDFF;">,</span><span style="color:#F78C6C;">2</span><span style="color:#89DDFF;">,</span><span style="color:#F78C6C;">3</span><span style="color:#89DDFF;">,</span><span style="color:#F78C6C;">4</span><span style="color:#89DDFF;">)</span></span>
<span class="line"><span style="color:#A6ACCD;">gl_dict </span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">{</span><span style="color:#89DDFF;">&quot;</span><span style="color:#C3E88D;">name</span><span style="color:#89DDFF;">&quot;</span><span style="color:#89DDFF;">:</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">&#39;</span><span style="color:#C3E88D;">deeper</span><span style="color:#89DDFF;">&#39;</span><span style="color:#89DDFF;">,</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">&#39;</span><span style="color:#C3E88D;">age</span><span style="color:#89DDFF;">&#39;</span><span style="color:#89DDFF;">:</span><span style="color:#F78C6C;">24</span><span style="color:#89DDFF;">}</span></span>
<span class="line"></span>
<span class="line"><span style="color:#89DDFF;font-style:italic;">&#39;&#39;&#39;</span><span style="color:#676E95;font-style:italic;">直接传参</span><span style="color:#89DDFF;font-style:italic;">&#39;&#39;&#39;</span></span>
<span class="line"><span style="color:#82AAFF;">demo</span><span style="color:#89DDFF;">(</span><span style="color:#82AAFF;">gl_nums</span><span style="color:#89DDFF;">,</span><span style="color:#82AAFF;"> gl_dict</span><span style="color:#89DDFF;">)</span><span style="color:#A6ACCD;"> </span></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># ---------- 显然不是我们想要的数据 -----------</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># args =&gt; ((1, 2, 3, 4), {&#39;name&#39;: &#39;deeper&#39;, &#39;age&#39;: 24})</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># kwargs =&gt; {}</span></span>
<span class="line"></span>
<span class="line"></span>
<span class="line"><span style="color:#89DDFF;font-style:italic;">&#39;&#39;&#39;</span><span style="color:#676E95;font-style:italic;">下面进行拆包</span><span style="color:#89DDFF;font-style:italic;">&#39;&#39;&#39;</span></span>
<span class="line"><span style="color:#82AAFF;">demo</span><span style="color:#89DDFF;">(*</span><span style="color:#82AAFF;">gl_nums</span><span style="color:#89DDFF;">,</span><span style="color:#82AAFF;"> </span><span style="color:#89DDFF;">**</span><span style="color:#82AAFF;">gl_dict</span><span style="color:#89DDFF;">)</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># args =&gt;  (1, 2, 3, 4)</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># kwargs =&gt;  {&#39;name&#39;: &#39;deeper&#39;, &#39;age&#39;: 24}</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br><span class="line-number">17</span><br><span class="line-number">18</span><br></div></div><h2 id="示例-基于键匹配和追加字典" tabindex="-1">示例：基于键匹配和追加字典 <a class="header-anchor" href="#示例-基于键匹配和追加字典" aria-label="Permalink to &quot;示例：基于键匹配和追加字典&quot;">​</a></h2><div class="tip custom-block"><p class="custom-block-title">已知一个数据集合（lst），处理返回指定格式的数据如下:</p><blockquote><p>[</p><p>​ {&quot;name&quot;: &quot;bob&quot;, &quot;children&quot;: [ {&quot;id&quot;: 1, &quot;age&quot;: 24}, { &quot;id&quot;: 2, &quot;age&quot;: 26 } ]},</p><p>​ {&quot;name&quot;: &quot;tom&quot;, &quot;children&quot;: [ {&quot;id&quot;: 3, &quot;age&quot;: 22}, {&quot;id&quot;: 4, &quot;age&quot;: 27}, {&quot;id&quot;: 5, &quot;age&quot;: 23}]},</p><p>​ { &quot;name&quot;: &quot;sarah&quot;, &quot;children&quot;: [{ &quot;id&quot;: 6, &quot;age&quot;: 28}]},</p><p>​ { &quot;name&quot;: &quot;jack&quot;, &quot;children&quot;: [{ &quot;id&quot;: 7, &quot;age&quot;: 25 }]}</p><p>]</p></blockquote></div><div class="language-python line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">python</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#676E95;font-style:italic;"># 已知数据集合</span></span>
<span class="line"><span style="color:#A6ACCD;">lst </span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">[</span></span>
<span class="line"><span style="color:#A6ACCD;">    </span><span style="color:#89DDFF;">{</span><span style="color:#89DDFF;">&#39;</span><span style="color:#C3E88D;">id</span><span style="color:#89DDFF;">&#39;</span><span style="color:#89DDFF;">:</span><span style="color:#F78C6C;">1</span><span style="color:#89DDFF;">,</span><span style="color:#89DDFF;">&#39;</span><span style="color:#C3E88D;">name</span><span style="color:#89DDFF;">&#39;</span><span style="color:#89DDFF;">:</span><span style="color:#89DDFF;">&#39;</span><span style="color:#C3E88D;">bob</span><span style="color:#89DDFF;">&#39;</span><span style="color:#89DDFF;">,</span><span style="color:#89DDFF;">&#39;</span><span style="color:#C3E88D;">age</span><span style="color:#89DDFF;">&#39;</span><span style="color:#89DDFF;">:</span><span style="color:#F78C6C;">24</span><span style="color:#89DDFF;">},</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">{</span><span style="color:#89DDFF;">&#39;</span><span style="color:#C3E88D;">id</span><span style="color:#89DDFF;">&#39;</span><span style="color:#89DDFF;">:</span><span style="color:#F78C6C;">2</span><span style="color:#89DDFF;">,</span><span style="color:#89DDFF;">&#39;</span><span style="color:#C3E88D;">name</span><span style="color:#89DDFF;">&#39;</span><span style="color:#89DDFF;">:</span><span style="color:#89DDFF;">&#39;</span><span style="color:#C3E88D;">bob</span><span style="color:#89DDFF;">&#39;</span><span style="color:#89DDFF;">,</span><span style="color:#89DDFF;">&#39;</span><span style="color:#C3E88D;">age</span><span style="color:#89DDFF;">&#39;</span><span style="color:#89DDFF;">:</span><span style="color:#F78C6C;">26</span><span style="color:#89DDFF;">},</span></span>
<span class="line"><span style="color:#A6ACCD;">    </span><span style="color:#89DDFF;">{</span><span style="color:#89DDFF;">&#39;</span><span style="color:#C3E88D;">id</span><span style="color:#89DDFF;">&#39;</span><span style="color:#89DDFF;">:</span><span style="color:#F78C6C;">3</span><span style="color:#89DDFF;">,</span><span style="color:#89DDFF;">&#39;</span><span style="color:#C3E88D;">name</span><span style="color:#89DDFF;">&#39;</span><span style="color:#89DDFF;">:</span><span style="color:#89DDFF;">&#39;</span><span style="color:#C3E88D;">tom</span><span style="color:#89DDFF;">&#39;</span><span style="color:#89DDFF;">,</span><span style="color:#89DDFF;">&#39;</span><span style="color:#C3E88D;">age</span><span style="color:#89DDFF;">&#39;</span><span style="color:#89DDFF;">:</span><span style="color:#F78C6C;">22</span><span style="color:#89DDFF;">},</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">{</span><span style="color:#89DDFF;">&#39;</span><span style="color:#C3E88D;">id</span><span style="color:#89DDFF;">&#39;</span><span style="color:#89DDFF;">:</span><span style="color:#F78C6C;">4</span><span style="color:#89DDFF;">,</span><span style="color:#89DDFF;">&#39;</span><span style="color:#C3E88D;">name</span><span style="color:#89DDFF;">&#39;</span><span style="color:#89DDFF;">:</span><span style="color:#89DDFF;">&#39;</span><span style="color:#C3E88D;">tom</span><span style="color:#89DDFF;">&#39;</span><span style="color:#89DDFF;">,</span><span style="color:#89DDFF;">&#39;</span><span style="color:#C3E88D;">age</span><span style="color:#89DDFF;">&#39;</span><span style="color:#89DDFF;">:</span><span style="color:#F78C6C;">27</span><span style="color:#89DDFF;">},</span></span>
<span class="line"><span style="color:#A6ACCD;">    </span><span style="color:#89DDFF;">{</span><span style="color:#89DDFF;">&#39;</span><span style="color:#C3E88D;">id</span><span style="color:#89DDFF;">&#39;</span><span style="color:#89DDFF;">:</span><span style="color:#F78C6C;">5</span><span style="color:#89DDFF;">,</span><span style="color:#89DDFF;">&#39;</span><span style="color:#C3E88D;">name</span><span style="color:#89DDFF;">&#39;</span><span style="color:#89DDFF;">:</span><span style="color:#89DDFF;">&#39;</span><span style="color:#C3E88D;">tom</span><span style="color:#89DDFF;">&#39;</span><span style="color:#89DDFF;">,</span><span style="color:#89DDFF;">&#39;</span><span style="color:#C3E88D;">age</span><span style="color:#89DDFF;">&#39;</span><span style="color:#89DDFF;">:</span><span style="color:#F78C6C;">23</span><span style="color:#89DDFF;">},</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">{</span><span style="color:#89DDFF;">&#39;</span><span style="color:#C3E88D;">id</span><span style="color:#89DDFF;">&#39;</span><span style="color:#89DDFF;">:</span><span style="color:#F78C6C;">6</span><span style="color:#89DDFF;">,</span><span style="color:#89DDFF;">&#39;</span><span style="color:#C3E88D;">name</span><span style="color:#89DDFF;">&#39;</span><span style="color:#89DDFF;">:</span><span style="color:#89DDFF;">&#39;</span><span style="color:#C3E88D;">sarah</span><span style="color:#89DDFF;">&#39;</span><span style="color:#89DDFF;">,</span><span style="color:#89DDFF;">&#39;</span><span style="color:#C3E88D;">age</span><span style="color:#89DDFF;">&#39;</span><span style="color:#89DDFF;">:</span><span style="color:#F78C6C;">28</span><span style="color:#89DDFF;">},</span></span>
<span class="line"><span style="color:#A6ACCD;">    </span><span style="color:#89DDFF;">{</span><span style="color:#89DDFF;">&#39;</span><span style="color:#C3E88D;">id</span><span style="color:#89DDFF;">&#39;</span><span style="color:#89DDFF;">:</span><span style="color:#F78C6C;">7</span><span style="color:#89DDFF;">,</span><span style="color:#89DDFF;">&#39;</span><span style="color:#C3E88D;">name</span><span style="color:#89DDFF;">&#39;</span><span style="color:#89DDFF;">:</span><span style="color:#89DDFF;">&#39;</span><span style="color:#C3E88D;">jack</span><span style="color:#89DDFF;">&#39;</span><span style="color:#89DDFF;">,</span><span style="color:#89DDFF;">&#39;</span><span style="color:#C3E88D;">age</span><span style="color:#89DDFF;">&#39;</span><span style="color:#89DDFF;">:</span><span style="color:#F78C6C;">25</span><span style="color:#89DDFF;">}</span></span>
<span class="line"><span style="color:#89DDFF;">]</span></span>
<span class="line"></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># </span><span style="color:#89DDFF;font-style:italic;">TODO</span><span style="color:#676E95;font-style:italic;"> ...&quot;&quot;&quot;</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># 1.获取用户名称，且不重复</span></span>
<span class="line"><span style="color:#A6ACCD;">names </span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">[</span><span style="color:#A6ACCD;"> d</span><span style="color:#89DDFF;">.</span><span style="color:#82AAFF;">get</span><span style="color:#89DDFF;">(</span><span style="color:#89DDFF;">&#39;</span><span style="color:#C3E88D;">name</span><span style="color:#89DDFF;">&#39;</span><span style="color:#89DDFF;">)</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;font-style:italic;">for</span><span style="color:#A6ACCD;"> d </span><span style="color:#89DDFF;font-style:italic;">in</span><span style="color:#A6ACCD;"> lst </span><span style="color:#89DDFF;">]</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># 2.去重</span></span>
<span class="line"><span style="color:#A6ACCD;">names </span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">[</span><span style="color:#A6ACCD;">name </span><span style="color:#89DDFF;font-style:italic;">for</span><span style="color:#A6ACCD;"> i</span><span style="color:#89DDFF;">,</span><span style="color:#A6ACCD;">name </span><span style="color:#89DDFF;font-style:italic;">in</span><span style="color:#A6ACCD;"> </span><span style="color:#82AAFF;">enumerate</span><span style="color:#89DDFF;">(</span><span style="color:#82AAFF;">names</span><span style="color:#89DDFF;">)</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;font-style:italic;">if</span><span style="color:#A6ACCD;"> name </span><span style="color:#89DDFF;">not</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">in</span><span style="color:#A6ACCD;"> names</span><span style="color:#89DDFF;">[:</span><span style="color:#A6ACCD;">i</span><span style="color:#89DDFF;">]]</span></span>
<span class="line"><span style="color:#82AAFF;">print</span><span style="color:#89DDFF;">(</span><span style="color:#82AAFF;">names</span><span style="color:#89DDFF;">)</span><span style="color:#A6ACCD;"> </span><span style="color:#676E95;font-style:italic;"># [&#39;bob&#39;, &#39;sarah&#39;, &#39;jack&#39;]</span></span>
<span class="line"></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># 3.处理数据</span></span>
<span class="line"><span style="color:#A6ACCD;">column </span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">(</span><span style="color:#89DDFF;">&#39;</span><span style="color:#C3E88D;">id</span><span style="color:#89DDFF;">&#39;</span><span style="color:#89DDFF;">,</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">&#39;</span><span style="color:#C3E88D;">age</span><span style="color:#89DDFF;">&#39;</span><span style="color:#89DDFF;">)</span></span>
<span class="line"><span style="color:#A6ACCD;">result </span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">[]</span><span style="color:#A6ACCD;">  </span><span style="color:#676E95;font-style:italic;"># 存放结果集</span></span>
<span class="line"><span style="color:#89DDFF;font-style:italic;">for</span><span style="color:#A6ACCD;"> name </span><span style="color:#89DDFF;font-style:italic;">in</span><span style="color:#A6ACCD;"> names</span><span style="color:#89DDFF;">:</span></span>
<span class="line"><span style="color:#A6ACCD;">		children </span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">[]</span></span>
<span class="line"><span style="color:#A6ACCD;">  	</span><span style="color:#89DDFF;font-style:italic;">for</span><span style="color:#A6ACCD;"> d </span><span style="color:#89DDFF;font-style:italic;">in</span><span style="color:#A6ACCD;"> lst</span><span style="color:#89DDFF;">:</span></span>
<span class="line"><span style="color:#A6ACCD;">    		</span><span style="color:#89DDFF;font-style:italic;">if</span><span style="color:#A6ACCD;"> d</span><span style="color:#89DDFF;">.</span><span style="color:#82AAFF;">get</span><span style="color:#89DDFF;">(</span><span style="color:#89DDFF;">&#39;</span><span style="color:#C3E88D;">name</span><span style="color:#89DDFF;">&#39;</span><span style="color:#89DDFF;">)</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">==</span><span style="color:#A6ACCD;"> name</span><span style="color:#89DDFF;">:</span></span>
<span class="line"><span style="color:#A6ACCD;">          	children</span><span style="color:#89DDFF;">.</span><span style="color:#82AAFF;">append</span><span style="color:#89DDFF;">({</span><span style="color:#82AAFF;"> k</span><span style="color:#89DDFF;">:</span><span style="color:#82AAFF;"> v </span><span style="color:#89DDFF;font-style:italic;">for</span><span style="color:#82AAFF;"> k</span><span style="color:#89DDFF;">,</span><span style="color:#82AAFF;">v </span><span style="color:#89DDFF;font-style:italic;">in</span><span style="color:#82AAFF;"> d</span><span style="color:#89DDFF;">.</span><span style="color:#82AAFF;">items</span><span style="color:#89DDFF;">()</span><span style="color:#82AAFF;"> </span><span style="color:#89DDFF;font-style:italic;">if</span><span style="color:#82AAFF;"> k </span><span style="color:#89DDFF;">in</span><span style="color:#82AAFF;"> column </span><span style="color:#89DDFF;">})</span></span>
<span class="line"><span style="color:#A6ACCD;">    result</span><span style="color:#89DDFF;">.</span><span style="color:#82AAFF;">append</span><span style="color:#89DDFF;">({</span><span style="color:#89DDFF;">&quot;</span><span style="color:#C3E88D;">name</span><span style="color:#89DDFF;">&quot;</span><span style="color:#89DDFF;">:</span><span style="color:#82AAFF;"> name</span><span style="color:#89DDFF;">,</span><span style="color:#82AAFF;"> </span><span style="color:#89DDFF;">&quot;</span><span style="color:#C3E88D;">children</span><span style="color:#89DDFF;">&quot;</span><span style="color:#89DDFF;">:</span><span style="color:#82AAFF;"> children</span><span style="color:#89DDFF;">})</span></span>
<span class="line"></span>
<span class="line"><span style="color:#82AAFF;">print</span><span style="color:#89DDFF;">(</span><span style="color:#82AAFF;">result</span><span style="color:#89DDFF;">)</span><span style="color:#A6ACCD;"> </span><span style="color:#676E95;font-style:italic;"># 打印结果数据</span></span>
<span class="line"><span style="color:#89DDFF;font-style:italic;">&#39;&#39;&#39;</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;">[</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;">    { &quot;name&quot;: &quot;bob&quot;, &quot;children&quot;: [</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;">        { &quot;id&quot;: 1, &quot;age&quot;: 24 },{ &quot;id&quot;: 2, &quot;age&quot;: 26 }</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;">    ] },</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;">    { &quot;name&quot;: &quot;tom&quot;, &quot;children&quot;: [</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;">        { &quot;id&quot;: 3, &quot;age&quot;: 22 },</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;">        { &quot;id&quot;: 4, &quot;age&quot;: 27 },</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;">        { &quot;id&quot;: 5, &quot;age&quot;: 23 }</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;">    ] },</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;">    { &quot;name&quot;: &quot;sarah&quot;, &quot;children&quot;: [{ &quot;id&quot;: 6, &quot;age&quot;: 28}]},</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;">    { &quot;name&quot;: &quot;jack&quot;, &quot;children&quot;: [{ &quot;id&quot;: 7, &quot;age&quot;: 25 }]}</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;">]</span></span>
<span class="line"><span style="color:#89DDFF;font-style:italic;">&#39;&#39;&#39;</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br><span class="line-number">17</span><br><span class="line-number">18</span><br><span class="line-number">19</span><br><span class="line-number">20</span><br><span class="line-number">21</span><br><span class="line-number">22</span><br><span class="line-number">23</span><br><span class="line-number">24</span><br><span class="line-number">25</span><br><span class="line-number">26</span><br><span class="line-number">27</span><br><span class="line-number">28</span><br><span class="line-number">29</span><br><span class="line-number">30</span><br><span class="line-number">31</span><br><span class="line-number">32</span><br><span class="line-number">33</span><br><span class="line-number">34</span><br><span class="line-number">35</span><br><span class="line-number">36</span><br><span class="line-number">37</span><br><span class="line-number">38</span><br><span class="line-number">39</span><br><span class="line-number">40</span><br></div></div><h2 id="三元表达式-1" tabindex="-1">三元表达式 <a class="header-anchor" href="#三元表达式-1" aria-label="Permalink to &quot;三元表达式&quot;">​</a></h2><div class="language-python line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">python</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#A6ACCD;">sex </span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;"> </span><span style="color:#F78C6C;">1</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;font-style:italic;">if</span><span style="color:#A6ACCD;"> </span><span style="color:#F78C6C;">10</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">&gt;</span><span style="color:#A6ACCD;"> </span><span style="color:#F78C6C;">0</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;font-style:italic;">else</span><span style="color:#A6ACCD;"> </span><span style="color:#F78C6C;">0</span></span>
<span class="line"></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># 三个值比较: </span></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># typed = idx ? (idx == 1 ? 2 : 3) : 1</span></span>
<span class="line"><span style="color:#A6ACCD;">idx </span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;"> </span><span style="color:#F78C6C;">0</span><span style="color:#A6ACCD;"> </span><span style="color:#676E95;font-style:italic;"># 根据索引来判断 typed</span></span>
<span class="line"><span style="color:#A6ACCD;">typed </span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;"> </span><span style="color:#F78C6C;">3</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;font-style:italic;">if</span><span style="color:#A6ACCD;"> i </span><span style="color:#89DDFF;">==</span><span style="color:#A6ACCD;"> </span><span style="color:#F78C6C;">2</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;font-style:italic;">else</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">(</span><span style="color:#F78C6C;">2</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;font-style:italic;">if</span><span style="color:#A6ACCD;"> i </span><span style="color:#89DDFF;">==</span><span style="color:#A6ACCD;"> </span><span style="color:#F78C6C;">1</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;font-style:italic;">else</span><span style="color:#A6ACCD;"> </span><span style="color:#F78C6C;">1</span><span style="color:#89DDFF;">)</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br></div></div><h2 id="身份运算符" tabindex="-1">身份运算符 <a class="header-anchor" href="#身份运算符" aria-label="Permalink to &quot;身份运算符&quot;">​</a></h2><ul><li>in 、not in</li></ul><table><thead><tr><th style="text-align:center;">运算符</th><th style="text-align:left;">描述</th></tr></thead><tbody><tr><td style="text-align:center;">in</td><td style="text-align:left;">如果在指定的序列中找到值返回 True，否则返回 False</td></tr><tr><td style="text-align:center;">not in</td><td style="text-align:left;">如果在指定的序列中没有找到值返回 True，否则返回 False</td></tr></tbody></table><div class="language-python line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">python</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#FFCB6B;">list</span><span style="color:#89DDFF;">=[</span><span style="color:#F78C6C;">1</span><span style="color:#89DDFF;">,</span><span style="color:#89DDFF;">&#39;</span><span style="color:#C3E88D;">5</span><span style="color:#89DDFF;">&#39;</span><span style="color:#89DDFF;">,</span><span style="color:#89DDFF;">&#39;</span><span style="color:#C3E88D;">s</span><span style="color:#89DDFF;">&#39;</span><span style="color:#89DDFF;">,</span><span style="color:#89DDFF;">&#39;</span><span style="color:#C3E88D;">cf</span><span style="color:#89DDFF;">&#39;</span><span style="color:#89DDFF;">]</span></span>
<span class="line"></span>
<span class="line"><span style="color:#82AAFF;">print</span><span style="color:#89DDFF;">(</span><span style="color:#89DDFF;">&#39;</span><span style="color:#A6ACCD;">\t</span><span style="color:#C3E88D;">1 </span><span style="color:#F78C6C;">%s</span><span style="color:#C3E88D;"> 列表list中</span><span style="color:#89DDFF;">&#39;</span><span style="color:#82AAFF;"> </span><span style="color:#89DDFF;">%</span><span style="color:#82AAFF;"> </span><span style="color:#89DDFF;">(</span><span style="color:#89DDFF;">&#39;</span><span style="color:#C3E88D;">in</span><span style="color:#89DDFF;">&#39;</span><span style="color:#82AAFF;"> </span><span style="color:#89DDFF;font-style:italic;">if</span><span style="color:#82AAFF;"> </span><span style="color:#F78C6C;">1</span><span style="color:#82AAFF;"> </span><span style="color:#89DDFF;">in</span><span style="color:#82AAFF;"> </span><span style="color:#FFCB6B;">list</span><span style="color:#82AAFF;"> </span><span style="color:#89DDFF;font-style:italic;">else</span><span style="color:#82AAFF;"> </span><span style="color:#89DDFF;">&#39;</span><span style="color:#C3E88D;">not in</span><span style="color:#89DDFF;">&#39;</span><span style="color:#89DDFF;">))</span><span style="color:#A6ACCD;"> </span><span style="color:#676E95;font-style:italic;"># in</span></span>
<span class="line"><span style="color:#82AAFF;">print</span><span style="color:#89DDFF;">(</span><span style="color:#89DDFF;">&#39;</span><span style="color:#A6ACCD;">\t</span><span style="color:#C3E88D;">1在列表list中 =&gt; </span><span style="color:#89DDFF;">&#39;</span><span style="color:#89DDFF;">,</span><span style="color:#82AAFF;"> </span><span style="color:#F78C6C;">1</span><span style="color:#82AAFF;"> </span><span style="color:#89DDFF;font-style:italic;">in</span><span style="color:#82AAFF;"> </span><span style="color:#FFCB6B;">list</span><span style="color:#89DDFF;">)</span><span style="color:#A6ACCD;">       </span><span style="color:#676E95;font-style:italic;"># True</span></span>
<span class="line"><span style="color:#82AAFF;">print</span><span style="color:#89DDFF;">(</span><span style="color:#89DDFF;">&#39;</span><span style="color:#A6ACCD;">\t</span><span style="color:#C3E88D;">&quot;1&quot;在列表list中 =&gt; </span><span style="color:#89DDFF;">&#39;</span><span style="color:#89DDFF;">,</span><span style="color:#82AAFF;"> </span><span style="color:#89DDFF;">&#39;</span><span style="color:#C3E88D;">1</span><span style="color:#89DDFF;">&#39;</span><span style="color:#82AAFF;"> </span><span style="color:#89DDFF;font-style:italic;">in</span><span style="color:#82AAFF;"> </span><span style="color:#FFCB6B;">list</span><span style="color:#89DDFF;">)</span><span style="color:#A6ACCD;">   </span><span style="color:#676E95;font-style:italic;"># False</span></span>
<span class="line"><span style="color:#82AAFF;">print</span><span style="color:#89DDFF;">(</span><span style="color:#89DDFF;">&#39;</span><span style="color:#A6ACCD;">\t</span><span style="color:#C3E88D;">5在列表list中 =&gt; </span><span style="color:#89DDFF;">&#39;</span><span style="color:#89DDFF;">,</span><span style="color:#82AAFF;"> </span><span style="color:#F78C6C;">5</span><span style="color:#82AAFF;"> </span><span style="color:#89DDFF;font-style:italic;">in</span><span style="color:#82AAFF;"> </span><span style="color:#FFCB6B;">list</span><span style="color:#89DDFF;">)</span><span style="color:#A6ACCD;">       </span><span style="color:#676E95;font-style:italic;"># False</span></span>
<span class="line"><span style="color:#82AAFF;">print</span><span style="color:#89DDFF;">(</span><span style="color:#89DDFF;">&#39;</span><span style="color:#A6ACCD;">\t</span><span style="color:#C3E88D;">s在列表list中 =&gt; </span><span style="color:#89DDFF;">&#39;</span><span style="color:#89DDFF;">,</span><span style="color:#82AAFF;"> </span><span style="color:#89DDFF;">&#39;</span><span style="color:#C3E88D;">s</span><span style="color:#89DDFF;">&#39;</span><span style="color:#82AAFF;"> </span><span style="color:#89DDFF;font-style:italic;">in</span><span style="color:#82AAFF;"> </span><span style="color:#FFCB6B;">list</span><span style="color:#89DDFF;">)</span><span style="color:#A6ACCD;">     </span><span style="color:#676E95;font-style:italic;"># True</span></span>
<span class="line"><span style="color:#82AAFF;">print</span><span style="color:#89DDFF;">(</span><span style="color:#89DDFF;">&#39;</span><span style="color:#A6ACCD;">\t</span><span style="color:#C3E88D;">ss在列表list中 =&gt; </span><span style="color:#89DDFF;">&#39;</span><span style="color:#89DDFF;">,</span><span style="color:#82AAFF;"> </span><span style="color:#89DDFF;">&#39;</span><span style="color:#C3E88D;">ss</span><span style="color:#89DDFF;">&#39;</span><span style="color:#82AAFF;"> </span><span style="color:#89DDFF;font-style:italic;">in</span><span style="color:#82AAFF;"> </span><span style="color:#FFCB6B;">list</span><span style="color:#89DDFF;">)</span><span style="color:#A6ACCD;">   </span><span style="color:#676E95;font-style:italic;"># False</span></span>
<span class="line"><span style="color:#82AAFF;">print</span><span style="color:#89DDFF;">(</span><span style="color:#89DDFF;">&#39;</span><span style="color:#A6ACCD;">\t</span><span style="color:#C3E88D;">&quot;cf&quot;在列表list中 =&gt; </span><span style="color:#89DDFF;">&#39;</span><span style="color:#89DDFF;">,</span><span style="color:#82AAFF;"> </span><span style="color:#89DDFF;">&#39;</span><span style="color:#C3E88D;">cf</span><span style="color:#89DDFF;">&#39;</span><span style="color:#82AAFF;"> </span><span style="color:#89DDFF;font-style:italic;">in</span><span style="color:#82AAFF;"> </span><span style="color:#FFCB6B;">list</span><span style="color:#89DDFF;">)</span><span style="color:#A6ACCD;"> </span><span style="color:#676E95;font-style:italic;"># True</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br></div></div><ul><li>is、not is</li></ul><table><thead><tr><th style="text-align:center;">运算符</th><th>描述</th></tr></thead><tbody><tr><td style="text-align:center;">is</td><td>is 是判断两个标识符是不是引用自一个对象</td></tr><tr><td style="text-align:center;">is not</td><td>is not 是判断两个标识符是不是引用自不同对象</td></tr></tbody></table><div class="language-python line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">python</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#676E95;font-style:italic;">#-*- coding:utf-8 -*- python 3.6.2</span></span>
<span class="line"><span style="color:#A6ACCD;">a</span><span style="color:#89DDFF;">=</span><span style="color:#F78C6C;">1</span></span>
<span class="line"><span style="color:#A6ACCD;">b</span><span style="color:#89DDFF;">=</span><span style="color:#F78C6C;">1</span></span>
<span class="line"></span>
<span class="line"><span style="color:#A6ACCD;">lista</span><span style="color:#89DDFF;">=[</span><span style="color:#F78C6C;">1</span><span style="color:#89DDFF;">,</span><span style="color:#89DDFF;">&#39;</span><span style="color:#C3E88D;">5</span><span style="color:#89DDFF;">&#39;</span><span style="color:#89DDFF;">,</span><span style="color:#89DDFF;">&#39;</span><span style="color:#C3E88D;">s</span><span style="color:#89DDFF;">&#39;</span><span style="color:#89DDFF;">,</span><span style="color:#89DDFF;">&#39;</span><span style="color:#C3E88D;">cf</span><span style="color:#89DDFF;">&#39;</span><span style="color:#89DDFF;">]</span></span>
<span class="line"><span style="color:#A6ACCD;">listb</span><span style="color:#89DDFF;">=[</span><span style="color:#F78C6C;">1</span><span style="color:#89DDFF;">,</span><span style="color:#89DDFF;">&#39;</span><span style="color:#C3E88D;">5</span><span style="color:#89DDFF;">&#39;</span><span style="color:#89DDFF;">,</span><span style="color:#89DDFF;">&#39;</span><span style="color:#C3E88D;">s</span><span style="color:#89DDFF;">&#39;</span><span style="color:#89DDFF;">,</span><span style="color:#89DDFF;">&#39;</span><span style="color:#C3E88D;">cf</span><span style="color:#89DDFF;">&#39;</span><span style="color:#89DDFF;">]</span></span>
<span class="line"></span>
<span class="line"><span style="color:#82AAFF;">print</span><span style="color:#89DDFF;">(</span><span style="color:#89DDFF;">&#39;</span><span style="color:#C3E88D;">a is b</span><span style="color:#89DDFF;">&#39;</span><span style="color:#89DDFF;">,</span><span style="color:#82AAFF;"> a </span><span style="color:#89DDFF;font-style:italic;">is</span><span style="color:#82AAFF;"> b</span><span style="color:#89DDFF;">)</span><span style="color:#A6ACCD;">  					</span><span style="color:#676E95;font-style:italic;"># a is b True</span></span>
<span class="line"><span style="color:#82AAFF;">print</span><span style="color:#89DDFF;">(</span><span style="color:#89DDFF;">&#39;</span><span style="color:#C3E88D;">a == b</span><span style="color:#89DDFF;">&#39;</span><span style="color:#89DDFF;">,</span><span style="color:#82AAFF;"> a </span><span style="color:#89DDFF;">==</span><span style="color:#82AAFF;"> b</span><span style="color:#89DDFF;">)</span><span style="color:#A6ACCD;">  					</span><span style="color:#676E95;font-style:italic;"># a == b True</span></span>
<span class="line"><span style="color:#82AAFF;">print</span><span style="color:#89DDFF;">(</span><span style="color:#89DDFF;">&#39;</span><span style="color:#C3E88D;">lista is listb</span><span style="color:#89DDFF;">&#39;</span><span style="color:#89DDFF;">,</span><span style="color:#82AAFF;"> lista </span><span style="color:#89DDFF;font-style:italic;">is</span><span style="color:#82AAFF;"> listb</span><span style="color:#89DDFF;">)</span><span style="color:#A6ACCD;">  	</span><span style="color:#676E95;font-style:italic;"># lista is listb False</span></span>
<span class="line"><span style="color:#82AAFF;">print</span><span style="color:#89DDFF;">(</span><span style="color:#89DDFF;">&#39;</span><span style="color:#C3E88D;">lista == listb</span><span style="color:#89DDFF;">&#39;</span><span style="color:#89DDFF;">,</span><span style="color:#82AAFF;"> lista </span><span style="color:#89DDFF;">==</span><span style="color:#82AAFF;"> listb</span><span style="color:#89DDFF;">)</span><span style="color:#A6ACCD;">		</span><span style="color:#676E95;font-style:italic;"># lista == listb True</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br></div></div><p><strong>注意</strong></p><blockquote><p>is 与 == 区别： is 用于判断两个变量引用对象是否为同一个， == 用于判断引用变量的值是否相等。</p></blockquote><h2 id="单引号、双引号、三引号" tabindex="-1">单引号、双引号、三引号 <a class="header-anchor" href="#单引号、双引号、三引号" aria-label="Permalink to &quot;单引号、双引号、三引号&quot;">​</a></h2><ul><li><p>单引号：(&#39;&#39;)</p></li><li><p>双引号：(&quot;&quot;)</p></li><li><p>三引号：(&#39;&#39;&#39;) 和 (&quot;&quot;&quot;) 用法一致</p></li></ul><div class="language-python line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">python</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#A6ACCD;">sql </span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">&#39;&#39;&#39;</span></span>
<span class="line"><span style="color:#C3E88D;">INSERT INTO user(uname, phone, nick)</span></span>
<span class="line"><span style="color:#C3E88D;">VALUES (&#39;</span><span style="color:#F78C6C;">%(uname)s</span><span style="color:#C3E88D;">&#39;, &#39;</span><span style="color:#F78C6C;">%(phone)s</span><span style="color:#C3E88D;">&#39;, &#39;</span><span style="color:#F78C6C;">%(nick)s</span><span style="color:#C3E88D;">&#39;)</span></span>
<span class="line"><span style="color:#89DDFF;">&#39;&#39;&#39;</span></span>
<span class="line"><span style="color:#FFCB6B;">str</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;"> sql </span><span style="color:#89DDFF;">%</span><span style="color:#A6ACCD;"> </span><span style="color:#FFCB6B;">dict</span><span style="color:#89DDFF;">(</span><span style="color:#A6ACCD;font-style:italic;">uname</span><span style="color:#89DDFF;">=</span><span style="color:#89DDFF;">&quot;</span><span style="color:#C3E88D;">Admin</span><span style="color:#89DDFF;">&quot;</span><span style="color:#89DDFF;">,</span><span style="color:#82AAFF;"> </span><span style="color:#A6ACCD;font-style:italic;">phone</span><span style="color:#89DDFF;">=</span><span style="color:#89DDFF;">&quot;</span><span style="color:#C3E88D;">18588886666</span><span style="color:#89DDFF;">&quot;</span><span style="color:#89DDFF;">,</span><span style="color:#82AAFF;"> </span><span style="color:#A6ACCD;font-style:italic;">nick</span><span style="color:#89DDFF;">=</span><span style="color:#89DDFF;">&quot;</span><span style="color:#C3E88D;">系统管理员</span><span style="color:#89DDFF;">&quot;</span><span style="color:#89DDFF;">)</span></span>
<span class="line"><span style="color:#82AAFF;">print</span><span style="color:#89DDFF;">(</span><span style="color:#FFCB6B;">str</span><span style="color:#89DDFF;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#A6ACCD;">------------</span><span style="color:#89DDFF;">-</span></span>
<span class="line"><span style="color:#A6ACCD;">INSERT INTO </span><span style="color:#82AAFF;">user</span><span style="color:#89DDFF;">(</span><span style="color:#82AAFF;">uname</span><span style="color:#89DDFF;">,</span><span style="color:#82AAFF;"> phone</span><span style="color:#89DDFF;">,</span><span style="color:#82AAFF;"> nick</span><span style="color:#89DDFF;">)</span><span style="color:#A6ACCD;"> </span><span style="color:#82AAFF;">VALUES </span><span style="color:#89DDFF;">(</span><span style="color:#89DDFF;">&#39;</span><span style="color:#C3E88D;">Admin</span><span style="color:#89DDFF;">&#39;</span><span style="color:#89DDFF;">,</span><span style="color:#82AAFF;"> </span><span style="color:#89DDFF;">&#39;</span><span style="color:#C3E88D;">18588886666</span><span style="color:#89DDFF;">&#39;</span><span style="color:#89DDFF;">,</span><span style="color:#82AAFF;"> </span><span style="color:#89DDFF;">&#39;</span><span style="color:#C3E88D;">系统管理员</span><span style="color:#89DDFF;">&#39;</span><span style="color:#89DDFF;">)</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br></div></div><h2 id="🎉-使用-xlrd-处理数据" tabindex="-1">🎉 使用 xlrd 处理数据 <a class="header-anchor" href="#🎉-使用-xlrd-处理数据" aria-label="Permalink to &quot;🎉 使用 xlrd 处理数据&quot;">​</a></h2><ul><li>活动窗口(sheet)操作</li></ul><div class="language-python line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">python</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#89DDFF;font-style:italic;">import</span><span style="color:#A6ACCD;"> xlrd</span></span>
<span class="line"></span>
<span class="line"><span style="color:#A6ACCD;">book </span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;"> xlrd</span><span style="color:#89DDFF;">.</span><span style="color:#82AAFF;">open_workbook</span><span style="color:#89DDFF;">(</span><span style="color:#82AAFF;"> </span><span style="color:#C792EA;">r</span><span style="color:#89DDFF;">&#39;</span><span style="color:#C3E88D;">path/filename</span><span style="color:#89DDFF;">&#39;</span><span style="color:#82AAFF;"> </span><span style="color:#89DDFF;">)</span><span style="color:#A6ACCD;"> </span><span style="color:#676E95;font-style:italic;"># path/文件名</span></span>
<span class="line"></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># 获取所有的活动窗口</span></span>
<span class="line"><span style="color:#A6ACCD;">sheets </span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;"> book</span><span style="color:#89DDFF;">.</span><span style="color:#82AAFF;">sheets</span><span style="color:#89DDFF;">()</span></span>
<span class="line"></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># 获取索引窗口</span></span>
<span class="line"><span style="color:#A6ACCD;">sheet </span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;"> book</span><span style="color:#89DDFF;">.</span><span style="color:#82AAFF;">sheet_by_index</span><span style="color:#89DDFF;">(</span><span style="color:#F78C6C;">0</span><span style="color:#89DDFF;">)</span><span style="color:#A6ACCD;"> </span><span style="color:#676E95;font-style:italic;"># 第一个窗口 或者 book.sheets()[0]</span></span>
<span class="line"><span style="color:#A6ACCD;">sheet </span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;"> book</span><span style="color:#89DDFF;">.</span><span style="color:#82AAFF;">sheet_by_index</span><span style="color:#89DDFF;">(</span><span style="color:#F78C6C;">1</span><span style="color:#89DDFF;">)</span><span style="color:#A6ACCD;"> </span><span style="color:#676E95;font-style:italic;"># 第二个窗口</span></span>
<span class="line"></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># 获取名称是 sheet1 的窗口</span></span>
<span class="line"><span style="color:#A6ACCD;">sheet </span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;"> book</span><span style="color:#89DDFF;">.</span><span style="color:#82AAFF;">sheet_by_name</span><span style="color:#89DDFF;">(</span><span style="color:#89DDFF;">&#39;</span><span style="color:#C3E88D;">sheet1</span><span style="color:#89DDFF;">&#39;</span><span style="color:#89DDFF;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># 返回所有工作表的名称</span></span>
<span class="line"><span style="color:#A6ACCD;">sheetnames </span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;"> book</span><span style="color:#89DDFF;">.</span><span style="color:#82AAFF;">sheet_names</span><span style="color:#89DDFF;">()</span></span>
<span class="line"></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># 检查某个sheet1是否导入完毕</span></span>
<span class="line"><span style="color:#A6ACCD;">book</span><span style="color:#89DDFF;">.</span><span style="color:#82AAFF;">sheet_loaded</span><span style="color:#89DDFF;">(</span><span style="color:#89DDFF;">&#39;</span><span style="color:#C3E88D;">sheet1</span><span style="color:#89DDFF;">&#39;</span><span style="color:#82AAFF;"> </span><span style="color:#89DDFF;font-style:italic;">or</span><span style="color:#82AAFF;"> index</span><span style="color:#89DDFF;">)</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br><span class="line-number">17</span><br><span class="line-number">18</span><br><span class="line-number">19</span><br></div></div><ul><li>行操作</li></ul><div class="language-python line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">python</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#A6ACCD;">nrows </span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;"> book</span><span style="color:#89DDFF;">.</span><span style="color:#F07178;">nrows</span><span style="color:#A6ACCD;"> 	</span><span style="color:#676E95;font-style:italic;"># 获取 sheet 中的有效行数</span></span>
<span class="line"></span>
<span class="line"><span style="color:#A6ACCD;">book</span><span style="color:#89DDFF;">.</span><span style="color:#82AAFF;">row</span><span style="color:#89DDFF;">(</span><span style="color:#82AAFF;">rowx</span><span style="color:#89DDFF;">)</span><span style="color:#A6ACCD;">  	</span><span style="color:#676E95;font-style:italic;"># 返回行中所有的单元格对象组成的列表</span></span>
<span class="line"></span>
<span class="line"><span style="color:#A6ACCD;">book</span><span style="color:#89DDFF;">.</span><span style="color:#82AAFF;">row_slice</span><span style="color:#89DDFF;">(</span><span style="color:#82AAFF;">rowx</span><span style="color:#89DDFF;">)</span><span style="color:#676E95;font-style:italic;"># 返回行中所有的单元格对象组成的列表</span></span>
<span class="line"></span>
<span class="line"><span style="color:#A6ACCD;">book</span><span style="color:#89DDFF;">.</span><span style="color:#82AAFF;">row_types</span><span style="color:#89DDFF;">(</span><span style="color:#82AAFF;">rowx</span><span style="color:#89DDFF;">,</span><span style="color:#82AAFF;"> </span><span style="color:#A6ACCD;font-style:italic;">start_colx</span><span style="color:#89DDFF;">=</span><span style="color:#F78C6C;">0</span><span style="color:#89DDFF;">,</span><span style="color:#82AAFF;"> </span><span style="color:#A6ACCD;font-style:italic;">end_colx</span><span style="color:#89DDFF;">=None)</span><span style="color:#A6ACCD;">    </span><span style="color:#676E95;font-style:italic;">#返回行中所有单元格的数据类型组成的列表</span></span>
<span class="line"></span>
<span class="line"><span style="color:#A6ACCD;">book</span><span style="color:#89DDFF;">.</span><span style="color:#82AAFF;">row_values</span><span style="color:#89DDFF;">(</span><span style="color:#82AAFF;">rowx</span><span style="color:#89DDFF;">,</span><span style="color:#82AAFF;"> </span><span style="color:#A6ACCD;font-style:italic;">start_colx</span><span style="color:#89DDFF;">=</span><span style="color:#F78C6C;">0</span><span style="color:#89DDFF;">,</span><span style="color:#82AAFF;"> </span><span style="color:#A6ACCD;font-style:italic;">end_colx</span><span style="color:#89DDFF;">=None)</span><span style="color:#A6ACCD;">   </span><span style="color:#676E95;font-style:italic;">#返回行中所有单元格的数据组成的列表</span></span>
<span class="line"></span>
<span class="line"><span style="color:#A6ACCD;">book</span><span style="color:#89DDFF;">.</span><span style="color:#82AAFF;">row_len</span><span style="color:#89DDFF;">(</span><span style="color:#82AAFF;">rowx</span><span style="color:#89DDFF;">)</span><span style="color:#A6ACCD;">  </span><span style="color:#676E95;font-style:italic;"># 返回该列的有效单元格长度</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br></div></div><ul><li>列操作</li></ul><div class="language-python line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">python</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#A6ACCD;">ncols </span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;"> book</span><span style="color:#89DDFF;">.</span><span style="color:#F07178;">ncols</span><span style="color:#A6ACCD;"> 	</span><span style="color:#676E95;font-style:italic;"># 获取列表的有效列数</span></span>
<span class="line"></span>
<span class="line"><span style="color:#A6ACCD;">book</span><span style="color:#89DDFF;">.</span><span style="color:#82AAFF;">col</span><span style="color:#89DDFF;">(</span><span style="color:#82AAFF;">colx</span><span style="color:#89DDFF;">,</span><span style="color:#82AAFF;"> </span><span style="color:#A6ACCD;font-style:italic;">start_rowx</span><span style="color:#89DDFF;">=</span><span style="color:#F78C6C;">0</span><span style="color:#89DDFF;">,</span><span style="color:#82AAFF;"> </span><span style="color:#A6ACCD;font-style:italic;">end_rowx</span><span style="color:#89DDFF;">=None)</span><span style="color:#A6ACCD;">  </span><span style="color:#676E95;font-style:italic;"># 返回由该列中所有的单元格对象组成的列表</span></span>
<span class="line"></span>
<span class="line"><span style="color:#A6ACCD;">book</span><span style="color:#89DDFF;">.</span><span style="color:#82AAFF;">col_slice</span><span style="color:#89DDFF;">(</span><span style="color:#82AAFF;">colx</span><span style="color:#89DDFF;">,</span><span style="color:#82AAFF;"> </span><span style="color:#A6ACCD;font-style:italic;">start_rowx</span><span style="color:#89DDFF;">=</span><span style="color:#F78C6C;">0</span><span style="color:#89DDFF;">,</span><span style="color:#82AAFF;"> </span><span style="color:#A6ACCD;font-style:italic;">end_rowx</span><span style="color:#89DDFF;">=None)</span><span style="color:#A6ACCD;"> </span><span style="color:#676E95;font-style:italic;"># 返回由该列中所有的单元格对象组成的列表</span></span>
<span class="line"></span>
<span class="line"><span style="color:#A6ACCD;">book</span><span style="color:#89DDFF;">.</span><span style="color:#82AAFF;">col_types</span><span style="color:#89DDFF;">(</span><span style="color:#82AAFF;">colx</span><span style="color:#89DDFF;">,</span><span style="color:#82AAFF;"> </span><span style="color:#A6ACCD;font-style:italic;">start_rowx</span><span style="color:#89DDFF;">=</span><span style="color:#F78C6C;">0</span><span style="color:#89DDFF;">,</span><span style="color:#82AAFF;"> </span><span style="color:#A6ACCD;font-style:italic;">end_rowx</span><span style="color:#89DDFF;">=None)</span><span style="color:#A6ACCD;"> </span><span style="color:#676E95;font-style:italic;"># 返回由该列中所有单元格数据类型组成的列表</span></span>
<span class="line"></span>
<span class="line"><span style="color:#A6ACCD;">book</span><span style="color:#89DDFF;">.</span><span style="color:#82AAFF;">col_values</span><span style="color:#89DDFF;">(</span><span style="color:#82AAFF;">colx</span><span style="color:#89DDFF;">,</span><span style="color:#82AAFF;"> </span><span style="color:#A6ACCD;font-style:italic;">start_rowx</span><span style="color:#89DDFF;">=</span><span style="color:#F78C6C;">0</span><span style="color:#89DDFF;">,</span><span style="color:#82AAFF;"> </span><span style="color:#A6ACCD;font-style:italic;">end_rowx</span><span style="color:#89DDFF;">=None)</span><span style="color:#A6ACCD;"> </span><span style="color:#676E95;font-style:italic;"># 返回由该列中所有单元格的数据组成的列表</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br></div></div><ul><li>单元格操作</li></ul><div class="language-python line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">python</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#A6ACCD;">book</span><span style="color:#89DDFF;">.</span><span style="color:#82AAFF;">cell</span><span style="color:#89DDFF;">(</span><span style="color:#82AAFF;">rowx</span><span style="color:#89DDFF;">,</span><span style="color:#82AAFF;"> colx</span><span style="color:#89DDFF;">)</span><span style="color:#A6ACCD;"> 		 </span><span style="color:#676E95;font-style:italic;"># 返回第一个单元格对象</span></span>
<span class="line"></span>
<span class="line"><span style="color:#A6ACCD;">book</span><span style="color:#89DDFF;">.</span><span style="color:#82AAFF;">cell_type</span><span style="color:#89DDFF;">(</span><span style="color:#82AAFF;">rowx</span><span style="color:#89DDFF;">,</span><span style="color:#82AAFF;">colx</span><span style="color:#89DDFF;">)</span><span style="color:#A6ACCD;">    </span><span style="color:#676E95;font-style:italic;"># 返回单元格中的数据类型</span></span>
<span class="line"></span>
<span class="line"><span style="color:#A6ACCD;">book</span><span style="color:#89DDFF;">.</span><span style="color:#82AAFF;">cell_value</span><span style="color:#89DDFF;">(</span><span style="color:#82AAFF;">rowx</span><span style="color:#89DDFF;">,</span><span style="color:#82AAFF;">colx</span><span style="color:#89DDFF;">)</span><span style="color:#A6ACCD;">   </span><span style="color:#676E95;font-style:italic;"># 返回单元格中的数据</span></span>
<span class="line"></span>
<span class="line"><span style="color:#A6ACCD;">book</span><span style="color:#89DDFF;">.</span><span style="color:#82AAFF;">cell_xf_index</span><span style="color:#89DDFF;">(</span><span style="color:#82AAFF;">rowx</span><span style="color:#89DDFF;">,</span><span style="color:#82AAFF;"> colx</span><span style="color:#89DDFF;">)</span><span style="color:#A6ACCD;">   </span><span style="color:#676E95;font-style:italic;"># 暂时还没有搞懂</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br></div></div><h2 id="🎉-示例-将excel导入mysql" tabindex="-1">🎉 示例: 将Excel导入MySQL <a class="header-anchor" href="#🎉-示例-将excel导入mysql" aria-label="Permalink to &quot;🎉 示例: 将Excel导入MySQL&quot;">​</a></h2><div class="language-python line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">python</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#89DDFF;font-style:italic;">&quot;&quot;&quot;</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;">功能：将Excel数据导入到MySQL数据库</span></span>
<span class="line"><span style="color:#89DDFF;font-style:italic;">&quot;&quot;&quot;</span></span>
<span class="line"><span style="color:#89DDFF;font-style:italic;">import</span><span style="color:#A6ACCD;"> xlrd</span></span>
<span class="line"><span style="color:#89DDFF;font-style:italic;">import</span><span style="color:#A6ACCD;"> MySQLdb</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># Open the workbook and define the worksheet</span></span>
<span class="line"><span style="color:#A6ACCD;">book </span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;"> xlrd</span><span style="color:#89DDFF;">.</span><span style="color:#82AAFF;">open_workbook</span><span style="color:#89DDFF;">(</span><span style="color:#89DDFF;">&quot;</span><span style="color:#C3E88D;">pytest.xls</span><span style="color:#89DDFF;">&quot;</span><span style="color:#89DDFF;">)</span></span>
<span class="line"><span style="color:#A6ACCD;">sheet </span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;"> book</span><span style="color:#89DDFF;">.</span><span style="color:#82AAFF;">sheet_by_name</span><span style="color:#89DDFF;">(</span><span style="color:#89DDFF;">&quot;</span><span style="color:#C3E88D;">source</span><span style="color:#89DDFF;">&quot;</span><span style="color:#89DDFF;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#676E95;font-style:italic;">#建立一个MySQL连接</span></span>
<span class="line"><span style="color:#A6ACCD;">database </span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;"> MySQLdb</span><span style="color:#89DDFF;">.</span><span style="color:#82AAFF;">connect </span><span style="color:#89DDFF;">(</span><span style="color:#A6ACCD;font-style:italic;">host</span><span style="color:#89DDFF;">=</span><span style="color:#89DDFF;">&quot;</span><span style="color:#C3E88D;">localhost</span><span style="color:#89DDFF;">&quot;</span><span style="color:#89DDFF;">,</span><span style="color:#82AAFF;"> </span><span style="color:#A6ACCD;font-style:italic;">user</span><span style="color:#82AAFF;"> </span><span style="color:#89DDFF;">=</span><span style="color:#82AAFF;"> </span><span style="color:#89DDFF;">&quot;</span><span style="color:#C3E88D;">root</span><span style="color:#89DDFF;">&quot;</span><span style="color:#89DDFF;">,</span><span style="color:#82AAFF;"> </span><span style="color:#A6ACCD;font-style:italic;">passwd</span><span style="color:#82AAFF;"> </span><span style="color:#89DDFF;">=</span><span style="color:#82AAFF;"> </span><span style="color:#89DDFF;">&quot;&quot;</span><span style="color:#89DDFF;">,</span><span style="color:#82AAFF;"> </span><span style="color:#A6ACCD;font-style:italic;">db</span><span style="color:#82AAFF;"> </span><span style="color:#89DDFF;">=</span><span style="color:#82AAFF;"> </span><span style="color:#89DDFF;">&quot;</span><span style="color:#C3E88D;">mysqlPython</span><span style="color:#89DDFF;">&quot;</span><span style="color:#89DDFF;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># 获得游标对象, 用于逐行遍历数据库数据</span></span>
<span class="line"><span style="color:#A6ACCD;">cursor </span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;"> database</span><span style="color:#89DDFF;">.</span><span style="color:#82AAFF;">cursor</span><span style="color:#89DDFF;">()</span></span>
<span class="line"></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># 创建插入SQL语句</span></span>
<span class="line"><span style="color:#A6ACCD;">query </span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">&quot;&quot;&quot;</span><span style="color:#C3E88D;">INSERT INTO orders (product, customer_type, rep, date, actual, expected, open_opportunities, closed_opportunities, city, state, zip, population, region) VALUES (</span><span style="color:#F78C6C;">%s</span><span style="color:#C3E88D;">, </span><span style="color:#F78C6C;">%s</span><span style="color:#C3E88D;">, </span><span style="color:#F78C6C;">%s</span><span style="color:#C3E88D;">, </span><span style="color:#F78C6C;">%s</span><span style="color:#C3E88D;">, </span><span style="color:#F78C6C;">%s</span><span style="color:#C3E88D;">, </span><span style="color:#F78C6C;">%s</span><span style="color:#C3E88D;">, </span><span style="color:#F78C6C;">%s</span><span style="color:#C3E88D;">, </span><span style="color:#F78C6C;">%s</span><span style="color:#C3E88D;">, </span><span style="color:#F78C6C;">%s</span><span style="color:#C3E88D;">, </span><span style="color:#F78C6C;">%s</span><span style="color:#C3E88D;">, </span><span style="color:#F78C6C;">%s</span><span style="color:#C3E88D;">, </span><span style="color:#F78C6C;">%s</span><span style="color:#C3E88D;">, </span><span style="color:#F78C6C;">%s</span><span style="color:#C3E88D;">)</span><span style="color:#89DDFF;">&quot;&quot;&quot;</span></span>
<span class="line"></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># 创建一个for循环迭代读取xls文件每行数据的, 从第二行开始是要跳过标题</span></span>
<span class="line"><span style="color:#89DDFF;font-style:italic;">for</span><span style="color:#A6ACCD;"> r </span><span style="color:#89DDFF;font-style:italic;">in</span><span style="color:#A6ACCD;"> </span><span style="color:#82AAFF;">range</span><span style="color:#89DDFF;">(</span><span style="color:#F78C6C;">1</span><span style="color:#89DDFF;">,</span><span style="color:#82AAFF;"> sheet</span><span style="color:#89DDFF;">.</span><span style="color:#F07178;">nrows</span><span style="color:#89DDFF;">):</span></span>
<span class="line"><span style="color:#A6ACCD;">      product  </span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;"> sheet</span><span style="color:#89DDFF;">.</span><span style="color:#82AAFF;">cell</span><span style="color:#89DDFF;">(</span><span style="color:#82AAFF;">r</span><span style="color:#89DDFF;">,).</span><span style="color:#F07178;">value</span></span>
<span class="line"><span style="color:#A6ACCD;">      customer </span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;"> sheet</span><span style="color:#89DDFF;">.</span><span style="color:#82AAFF;">cell</span><span style="color:#89DDFF;">(</span><span style="color:#82AAFF;">r</span><span style="color:#89DDFF;">,</span><span style="color:#F78C6C;">1</span><span style="color:#89DDFF;">).</span><span style="color:#F07178;">value</span></span>
<span class="line"><span style="color:#A6ACCD;">      rep      </span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;"> sheet</span><span style="color:#89DDFF;">.</span><span style="color:#82AAFF;">cell</span><span style="color:#89DDFF;">(</span><span style="color:#82AAFF;">r</span><span style="color:#89DDFF;">,</span><span style="color:#F78C6C;">2</span><span style="color:#89DDFF;">).</span><span style="color:#F07178;">value</span></span>
<span class="line"><span style="color:#A6ACCD;">      date     </span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;"> sheet</span><span style="color:#89DDFF;">.</span><span style="color:#82AAFF;">cell</span><span style="color:#89DDFF;">(</span><span style="color:#82AAFF;">r</span><span style="color:#89DDFF;">,</span><span style="color:#F78C6C;">3</span><span style="color:#89DDFF;">).</span><span style="color:#F07178;">value</span></span>
<span class="line"><span style="color:#A6ACCD;">      actual   </span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;"> sheet</span><span style="color:#89DDFF;">.</span><span style="color:#82AAFF;">cell</span><span style="color:#89DDFF;">(</span><span style="color:#82AAFF;">r</span><span style="color:#89DDFF;">,</span><span style="color:#F78C6C;">4</span><span style="color:#89DDFF;">).</span><span style="color:#F07178;">value</span></span>
<span class="line"><span style="color:#A6ACCD;">      expected </span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;"> sheet</span><span style="color:#89DDFF;">.</span><span style="color:#82AAFF;">cell</span><span style="color:#89DDFF;">(</span><span style="color:#82AAFF;">r</span><span style="color:#89DDFF;">,</span><span style="color:#F78C6C;">5</span><span style="color:#89DDFF;">).</span><span style="color:#F07178;">value</span></span>
<span class="line"><span style="color:#A6ACCD;">      </span><span style="color:#82AAFF;">open</span><span style="color:#A6ACCD;">     </span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;"> sheet</span><span style="color:#89DDFF;">.</span><span style="color:#82AAFF;">cell</span><span style="color:#89DDFF;">(</span><span style="color:#82AAFF;">r</span><span style="color:#89DDFF;">,</span><span style="color:#F78C6C;">6</span><span style="color:#89DDFF;">).</span><span style="color:#F07178;">value</span></span>
<span class="line"><span style="color:#A6ACCD;">      closed   </span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;"> sheet</span><span style="color:#89DDFF;">.</span><span style="color:#82AAFF;">cell</span><span style="color:#89DDFF;">(</span><span style="color:#82AAFF;">r</span><span style="color:#89DDFF;">,</span><span style="color:#F78C6C;">7</span><span style="color:#89DDFF;">).</span><span style="color:#F07178;">value</span></span>
<span class="line"><span style="color:#A6ACCD;">      city     </span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;"> sheet</span><span style="color:#89DDFF;">.</span><span style="color:#82AAFF;">cell</span><span style="color:#89DDFF;">(</span><span style="color:#82AAFF;">r</span><span style="color:#89DDFF;">,</span><span style="color:#F78C6C;">8</span><span style="color:#89DDFF;">).</span><span style="color:#F07178;">value</span></span>
<span class="line"><span style="color:#A6ACCD;">      state    </span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;"> sheet</span><span style="color:#89DDFF;">.</span><span style="color:#82AAFF;">cell</span><span style="color:#89DDFF;">(</span><span style="color:#82AAFF;">r</span><span style="color:#89DDFF;">,</span><span style="color:#F78C6C;">9</span><span style="color:#89DDFF;">).</span><span style="color:#F07178;">value</span></span>
<span class="line"><span style="color:#A6ACCD;">      </span><span style="color:#82AAFF;">zip</span><span style="color:#A6ACCD;">      </span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;"> sheet</span><span style="color:#89DDFF;">.</span><span style="color:#82AAFF;">cell</span><span style="color:#89DDFF;">(</span><span style="color:#82AAFF;">r</span><span style="color:#89DDFF;">,</span><span style="color:#F78C6C;">10</span><span style="color:#89DDFF;">).</span><span style="color:#F07178;">value</span></span>
<span class="line"><span style="color:#A6ACCD;">      pop      </span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;"> sheet</span><span style="color:#89DDFF;">.</span><span style="color:#82AAFF;">cell</span><span style="color:#89DDFF;">(</span><span style="color:#82AAFF;">r</span><span style="color:#89DDFF;">,</span><span style="color:#F78C6C;">11</span><span style="color:#89DDFF;">).</span><span style="color:#F07178;">value</span></span>
<span class="line"><span style="color:#A6ACCD;">      region   </span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;"> sheet</span><span style="color:#89DDFF;">.</span><span style="color:#82AAFF;">cell</span><span style="color:#89DDFF;">(</span><span style="color:#82AAFF;">r</span><span style="color:#89DDFF;">,</span><span style="color:#F78C6C;">12</span><span style="color:#89DDFF;">).</span><span style="color:#F07178;">value</span></span>
<span class="line"></span>
<span class="line"><span style="color:#A6ACCD;">      values </span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">(</span><span style="color:#A6ACCD;">product</span><span style="color:#89DDFF;">,</span><span style="color:#A6ACCD;"> customer</span><span style="color:#89DDFF;">,</span><span style="color:#A6ACCD;"> rep</span><span style="color:#89DDFF;">,</span><span style="color:#A6ACCD;"> date</span><span style="color:#89DDFF;">,</span><span style="color:#A6ACCD;"> actual</span><span style="color:#89DDFF;">,</span><span style="color:#A6ACCD;"> expected</span><span style="color:#89DDFF;">,</span><span style="color:#A6ACCD;"> </span><span style="color:#82AAFF;">open</span><span style="color:#89DDFF;">,</span><span style="color:#A6ACCD;"> closed</span><span style="color:#89DDFF;">,</span><span style="color:#A6ACCD;"> city</span><span style="color:#89DDFF;">,</span><span style="color:#A6ACCD;"> state</span><span style="color:#89DDFF;">,</span><span style="color:#A6ACCD;"> </span><span style="color:#82AAFF;">zip</span><span style="color:#89DDFF;">,</span><span style="color:#A6ACCD;"> pop</span><span style="color:#89DDFF;">,</span><span style="color:#A6ACCD;"> region</span><span style="color:#89DDFF;">)</span></span>
<span class="line"><span style="color:#A6ACCD;">    </span></span>
<span class="line"><span style="color:#A6ACCD;">      cursor</span><span style="color:#89DDFF;">.</span><span style="color:#82AAFF;">execute</span><span style="color:#89DDFF;">(</span><span style="color:#82AAFF;">query</span><span style="color:#89DDFF;">,</span><span style="color:#82AAFF;"> values</span><span style="color:#89DDFF;">)</span><span style="color:#A6ACCD;">	</span><span style="color:#676E95;font-style:italic;"># 执行sql语句</span></span>
<span class="line"></span>
<span class="line"><span style="color:#A6ACCD;">cursor</span><span style="color:#89DDFF;">.</span><span style="color:#82AAFF;">close</span><span style="color:#89DDFF;">()</span><span style="color:#A6ACCD;"> 		</span><span style="color:#676E95;font-style:italic;"># 关闭游标</span></span>
<span class="line"><span style="color:#A6ACCD;">database</span><span style="color:#89DDFF;">.</span><span style="color:#82AAFF;">commit</span><span style="color:#89DDFF;">()</span><span style="color:#A6ACCD;"> 	</span><span style="color:#676E95;font-style:italic;"># 提交</span></span>
<span class="line"><span style="color:#A6ACCD;">database</span><span style="color:#89DDFF;">.</span><span style="color:#82AAFF;">close</span><span style="color:#89DDFF;">()</span><span style="color:#A6ACCD;">	</span><span style="color:#676E95;font-style:italic;"># 关闭数据库连接</span></span>
<span class="line"></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># 打印结果</span></span>
<span class="line"><span style="color:#82AAFF;">print</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">&quot;&quot;</span></span>
<span class="line"><span style="color:#82AAFF;">print</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">&quot;</span><span style="color:#C3E88D;">Done! </span><span style="color:#89DDFF;">&quot;</span></span>
<span class="line"><span style="color:#82AAFF;">print</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">&quot;&quot;</span></span>
<span class="line"><span style="color:#A6ACCD;">columns </span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;"> </span><span style="color:#FFCB6B;">str</span><span style="color:#89DDFF;">(</span><span style="color:#82AAFF;">sheet</span><span style="color:#89DDFF;">.</span><span style="color:#F07178;">ncols</span><span style="color:#89DDFF;">)</span></span>
<span class="line"><span style="color:#A6ACCD;">rows </span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;"> </span><span style="color:#FFCB6B;">str</span><span style="color:#89DDFF;">(</span><span style="color:#82AAFF;">sheet</span><span style="color:#89DDFF;">.</span><span style="color:#F07178;">nrows</span><span style="color:#89DDFF;">)</span></span>
<span class="line"><span style="color:#82AAFF;">print</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">&quot;</span><span style="color:#C3E88D;">我刚导入了 </span><span style="color:#89DDFF;">&quot;</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">%</span><span style="color:#A6ACCD;">2B columns </span><span style="color:#89DDFF;">%</span><span style="color:#A6ACCD;">2B </span><span style="color:#89DDFF;">&quot;</span><span style="color:#C3E88D;"> 列 and </span><span style="color:#89DDFF;">&quot;</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">%</span><span style="color:#A6ACCD;">2B rows </span><span style="color:#89DDFF;">%</span><span style="color:#A6ACCD;">2B </span><span style="color:#89DDFF;">&quot;</span><span style="color:#C3E88D;"> 行数据到MySQL!</span><span style="color:#89DDFF;">&quot;</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br><span class="line-number">17</span><br><span class="line-number">18</span><br><span class="line-number">19</span><br><span class="line-number">20</span><br><span class="line-number">21</span><br><span class="line-number">22</span><br><span class="line-number">23</span><br><span class="line-number">24</span><br><span class="line-number">25</span><br><span class="line-number">26</span><br><span class="line-number">27</span><br><span class="line-number">28</span><br><span class="line-number">29</span><br><span class="line-number">30</span><br><span class="line-number">31</span><br><span class="line-number">32</span><br><span class="line-number">33</span><br><span class="line-number">34</span><br><span class="line-number">35</span><br><span class="line-number">36</span><br><span class="line-number">37</span><br><span class="line-number">38</span><br><span class="line-number">39</span><br><span class="line-number">40</span><br><span class="line-number">41</span><br><span class="line-number">42</span><br><span class="line-number">43</span><br><span class="line-number">44</span><br><span class="line-number">45</span><br><span class="line-number">46</span><br><span class="line-number">47</span><br><span class="line-number">48</span><br><span class="line-number">49</span><br></div></div><h2 id="经典文章" tabindex="-1">经典文章 <a class="header-anchor" href="#经典文章" aria-label="Permalink to &quot;经典文章&quot;">​</a></h2><ul><li><a href="https://www.runoob.com/python/python-100-examples.html" target="_blank" rel="noreferrer">Python100题</a></li><li><a href="https://www.zhihu.com/question/64649692" target="_blank" rel="noreferrer">知乎：Python 单引号中怎么引用变量</a></li></ul></div></div></main><footer class="VPDocFooter" data-v-0618013c data-v-1d44c82e><!--[--><!--]--><!----><div class="prev-next" data-v-1d44c82e><div class="pager" data-v-1d44c82e><a class="pager-link prev" href="/docs/backend/php-vender.html" data-v-1d44c82e><span class="desc" data-v-1d44c82e>Previous page</span><span class="title" data-v-1d44c82e>PHP 扩展插件</span></a></div><div class="has-prev pager" data-v-1d44c82e><a class="pager-link next" href="/docs/backend/shell.html" data-v-1d44c82e><span class="desc" data-v-1d44c82e>Next page</span><span class="title" data-v-1d44c82e>SHELL</span></a></div></div></footer><!--[--><!--]--></div></div></div><!--[--><!--]--></div></div><footer class="VPFooter has-sidebar" data-v-4f197c35 data-v-dfe4da57><div class="container" data-v-dfe4da57><p class="message" data-v-dfe4da57>Released under the MIT License.</p><p class="copyright" data-v-dfe4da57>Copyright © 2019-present Deeperee</p></div></footer><!--[--><!--]--></div></div>
    <script>__VP_HASH_MAP__ = JSON.parse("{\"backend_composer.md\":\"ee7790f5\",\"backend_api.md\":\"949a23be\",\"backend_database.md\":\"05849cab\",\"backend_dollar.md\":\"d0be0a24\",\"backend_index.md\":\"3b647050\",\"backend_fast-admin.md\":\"df07b96c\",\"backend_php-vender.md\":\"d40957ce\",\"backend_php-bc-function.md\":\"87c7cbe3\",\"backend_laravel.md\":\"ce4b1d78\",\"backend_php-advanced.md\":\"577c22e6\",\"backend_thinkphp6.md\":\"c7f68674\",\"backend_shell.md\":\"d55b3613\",\"environment_index.md\":\"5373858b\",\"environment_centos.md\":\"0019d7ac\",\"frontend_formdata.md\":\"3db3d25f\",\"environment_crontab.md\":\"c16d3a94\",\"frontend_canvas.md\":\"38b4856c\",\"environment_bt.md\":\"fe682394\",\"backend_python.md\":\"a9236c98\",\"frontend_await.md\":\"ddc5025b\",\"frontend_es6.md\":\"3e600e99\",\"backend_wechat.md\":\"435c4b09\",\"frontend_normalization.md\":\"92f2a6d4\",\"index.md\":\"e8f91319\",\"sharp-sword_httpie.md\":\"66de0137\",\"sharp-sword_map.md\":\"3cd7f82b\",\"frontend_overload.md\":\"90b7a3e4\",\"sharp-sword_brew.md\":\"60a41600\",\"sharp-sword_index.md\":\"1f53cfa4\",\"frontend_ui-packing.md\":\"3ed339e0\",\"sharp-sword_algolia.md\":\"77c04496\",\"frontend_vite.md\":\"fde8b60f\",\"sharp-sword_whistle.md\":\"9e86bed9\",\"frontend_nestjs.md\":\"c79bdd92\",\"sharp-sword_git.md\":\"60e04651\",\"sharp-sword_yarn.md\":\"b82caeae\",\"software_index.md\":\"dffc2ab6\",\"frontend_request.md\":\"5e510b40\",\"frontend_vue.md\":\"f25eaded\",\"frontend_index.md\":\"8104cd19\"}")
__VP_SITE_DATA__ = JSON.parse("{\"lang\":\"en-US\",\"dir\":\"ltr\",\"title\":\"中华文档库\",\"description\":\"A VitePress site\",\"base\":\"/docs/\",\"head\":[],\"appearance\":true,\"themeConfig\":{\"logo\":\"https://foruda.gitee.com/avatar/1662445450649625813/1624674_except-one_1662445449.png\",\"search\":{\"provider\":\"local\"},\"socialLinks\":[{\"title\":\"GITEE\",\"icon\":\"github\",\"link\":\"https://gitee.com/Except-one/\"},{\"title\":\"GITHUB\",\"icon\":\"github\",\"link\":\"https://github.com/deeperee/\"}],\"lastUpdatedText\":\"最近更新时间\",\"nav\":[{\"text\":\"利剑\",\"link\":\"/sharp-sword/\",\"activeMatch\":\"^/sharp-sword/\"},{\"text\":\"前端\",\"link\":\"/frontend/\",\"activeMatch\":\"^/frontend/\"},{\"text\":\"后端\",\"link\":\"/backend/\",\"activeMatch\":\"^/backend/\"},{\"text\":\"服务\",\"link\":\"/environment/\",\"activeMatch\":\"^/environment/\"},{\"text\":\"软件\",\"link\":\"/software/\",\"activeMatch\":\"^/software/\"}],\"sidebar\":{\"/sharp-sword/\":[{\"text\":\"欲要善其事,必先利其器\",\"collapsible\":true,\"items\":[{\"text\":\"node\",\"link\":\"/sharp-sword/#node\"},{\"text\":\"nvm\",\"link\":\"/sharp-sword/#nvm\"},{\"text\":\"npm\",\"link\":\"/sharp-sword/#npm\"},{\"text\":\"pnpm\",\"link\":\"/sharp-sword/#pnpm\"},{\"text\":\"nrm\",\"link\":\"/sharp-sword/#nrm\"},{\"text\":\"yarn\",\"link\":\"/sharp-sword/yarn\"},{\"text\":\"brew\",\"link\":\"/sharp-sword/brew\"},{\"text\":\"composer\",\"link\":\"/backend/composer\"},{\"text\":\"git\",\"link\":\"/sharp-sword/git\"},{\"text\":\"map 地图\",\"link\":\"/sharp-sword/map\"},{\"text\":\"whistle proxy\",\"link\":\"/sharp-sword/whistle\"},{\"text\":\"* algolia\",\"link\":\"/sharp-sword/algolia\"}]}],\"/frontend/\":[{\"items\":[{\"text\":\"前端集合\",\"link\":\"/frontend/index\"},{\"text\":\"Ajax封装\",\"link\":\"/frontend/request\"},{\"text\":\"Vite\",\"link\":\"/frontend/vite\"},{\"text\":\"Vue2/3\",\"link\":\"/frontend/vue\"},{\"text\":\"ES6语法糖\",\"link\":\"/frontend/es6\"},{\"text\":\"NestJs\",\"link\":\"/frontend/nestjs\"},{\"text\":\"消除<异步>的传染性\",\"link\":\"/frontend/await\"},{\"text\":\"JS实现函数的重载\",\"link\":\"/frontend/overload\"},{\"text\":\"参数归一化\",\"link\":\"/frontend/normalization\"},{\"text\":\"UI组件的二次封装\",\"link\":\"/frontend/ui-packing\"},{\"text\":\"Canvas 应用\",\"link\":\"/frontend/canvas\"}]}],\"/backend/\":[{\"items\":[{\"text\":\"HTTP状态码\",\"link\":\"/backend/index\"},{\"text\":\"API开发\",\"link\":\"/backend/api\"},{\"text\":\"Composer\",\"link\":\"/backend/composer\"},{\"text\":\"Database\",\"link\":\"/backend/database\"},{\"text\":\"Laravel 8.x\",\"link\":\"/backend/laravel\"},{\"text\":\"ThinkPHP 6.x\",\"link\":\"/backend/thinkphp6\"},{\"text\":\"Fast-admin\",\"link\":\"/backend/fast-admin\"},{\"text\":\"PHP 高级函数\",\"link\":\"/backend/php-advanced\"},{\"text\":\"PHP BC运算函数\",\"link\":\"/backend/php-bc-function\"},{\"text\":\"PHP 扩展插件\",\"link\":\"/backend/php-vender\"},{\"text\":\"Python3\",\"link\":\"/backend/python\"},{\"text\":\"SHELL\",\"link\":\"/backend/shell\"},{\"text\":\"微信开发\",\"link\":\"/backend/wechat\"},{\"text\":\"~~彩蛋~~\",\"link\":\"/backend/dollar\"}]}],\"/environment/\":[{\"text\":\"服务器环境\",\"collapsible\":true,\"items\":[{\"text\":\"CentOS 7.x\",\"link\":\"/environment/centos\"},{\"text\":\"Crontab 定时任务\",\"link\":\"/environment/crontab\"},{\"text\":\"BT-宝塔\",\"link\":\"/environment/bt\"}]}]},\"footer\":{\"message\":\"Released under the MIT License.\",\"copyright\":\"Copyright © 2019-present Deeperee\"}},\"locales\":{},\"scrollOffset\":90,\"cleanUrls\":false}")</script>
    
  </body>
</html>